Problems with drag'n'drop from IE - c#

My question is really simple and I don't know whether I am missing something or it is simply not allowed. I am trying to accept any content that has been selected in IE and dragged onto my app. All events fire as they should, and I am starting to analyze the content that I have received and this is where the fun begins.
When I ask for e.Data.GetFormats() in the string array, I can see clearly Text, HTML Format and Rich Text Format amongst other types.
But when I try to e.Data.GetDataPresent("Text") it returns false. Funny enough, when I try e.Data.GetData("Text") I get null too. (Was expected though)
My question is, should I be using something different to handle dragged content from IE? Or simply I can't access the data because it is from Internet Zone?
I forgot to add so later edit: - this is a .NET 2.0 Windows app and not asp.net nor a website :)
Thank you

Use Javascript for handling such tasks, it is fully compatible with the standard browsers.
You may want to program your own jQuery plugin for drag and drop
Here is one for dragging table rows

Related

Get (altered) textarea content from webBrowser element in C#

I've searched the web for 2 days now and am about to give up on this, but I'm soo close to the final solution... so you're my last hope. ;)
I have made a little C# application with Windows Forms GUI that uses a webBrowser element to display an HTML file with a TinyMCE editor embedded - this way I get a nice window with customizable editor functions I can use perfectly for my needs in this project.
I can set the textarea input for this editor window without problems thanks to this solution posted here on stackoverflow: https://stackoverflow.com/a/16322324/3498545
However I'm having big troubles reading text from this textarea. If I read the element by ID as shown (for setting content) in the solution above, I get the old text, as TinyMCE never really saves the changes.
But how do I get the input that my users will make in the textarea via TinyMCE? Is there some way to trigger a form send in HTML to get this input?
Thank you so much for you help!
Ok, to answer my own question (maybe others find this useful sometime later):
The changes of TinyMCE don't get written back to the textarea field in realtime, so I had to work around that. One solution would be to add something in the javascript header that writes every change back to the textarea immediately, however this caused problems for me as TinyMCE code clean up is not involved at this point.
My solution was to temporarily create a new file where the input of the TinyMCE field gets written directly into source code, which is a piece of cake to read back in C#.
The javascript code needed looks like this:
setup : function(editor){
editor.on('submit', function (){
tinymce.triggerSave();
document.writeln("<!DOCTYPE html><html><body><div id='content'>"+document.getElementById('textarea').value+"</div></body></html>")
document.close()
});
}
After that you can read the content in C# with the following code:
webBrowser.Document.GetElementById("content").InnerHtml
Now I can store HTML formatted code in my SQL database that can be managed and edited with a shiny interface. ;)

Display HTML in a silverlight application

I need to display HTML in my silverlight application and cannot find a way of doing it. I cannot use the web browser control as it needs to be able to run in or out of a browser.
Does anyone know of a good way to do this, because all I can think of doing at the moment is running replace methods on the text to just replace the tags with C# equivalents eg(<br /> to \n).
The way I do it is to check if the application is running inside the browser and change the means of display accordingly. If running inside the browser, I overlay the application with an IFrame, as I describe in this article: http://www.silverlightshow.net/items/Building-a-Silverlight-Line-Of-Business-Application-Part-6.aspx. Otherwise, I use the WebBrowser control. I have a control which does this all for you in the source code that accompanies my book, which is downloadable from the Apress website here: http://www.apress.com/book/downloadfile/4638.
Hope this helps...
Chris
I believe what you are looking for is HTML Bridge.
Edit I'm am actually now unsure if you'll still have access to javascript if you're running this OOB. I'm going to look into this some more and will further update. I'll still leave the answer up though for reference.
Second Edit Here is what I've found. HTML Bridge is disabled when you run silverlight out of browser. This disables access to the HTML DOM as well as Javascript. However, according to a comment on this site:
HTML Bridge is not available when you first install a OOB app. But you CAN force it if you modify the index.html in the folder where the app is installed just adding the enablehtmlaccess parameter.
It works!
You can even create dynamic HTML elements using the well-known methods of the HtmlPage class. You can even open a new browser window with the Navigate() method and its "_blank" parameter.
Keep in mind this information was posted about SL 3. Its possible that this may have changed, but I doubt it. So it seems that what you may want to do is build a script into the startup of your SL app that detects whether or not your app is running out of browser. If it is then you may want to have some script to call that can modify this file for you.
There recently was a similar question.
I posted a link there to an implementation that parses and displays HTML inline in Silverlight. Of course, it will work only with simple HTML, but maybe you can expand it to your needs.

Programmatically changing the destination printer for a WinForms WebBrowser control

I'm trying to use an invisible WebBrowser control to print a very simple HTML document. Our application requires that we be able to print several documents this way, and that they all can be sent to different printers. Unfortunately, I haven't been very successful in making the output go to the right printer.
The way it works right now is that before printing a document, the application determines which printer is to receive it, and sets the default printer accordingly. To do this it uses SetDefaultPrinter() imported from WinSpool.drv. If I step the code in debug mode I can clearly see that the default printer changes (and this change is reflected in the control panel UI), but the WebBrowser still insists on using the original default printer.
The MSDN documentation, from what I've seen, doesn't really provide a solution for this scenario. I would greatly appreciate some input on how I can accomplish this programmatically.
Given what you've said, perhaps if you restart the process which contains the web browser control (or the process which is the web browser control), after you change the default printer? That's the kind of thing I see happening here, for example.
I suppose it would be possible to fork off a background process that does the actual printing, but I'm really hoping for a simpler solution.
Forking was my first thought towards a probably-simplest solution.
Some other alternatives are as follows.
1). IE, which the webbrowser control is wrapping, exposes APIs via ActiveX. One of its/those APIs might let you specify the destination printer.
2). Some executables (I don't know about IE) have printto entries in the registry. For example, Acrobat Reader has an entry whose value is as follows:
""C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe"" /t "%1" "%2" "%3" "%4"
That's used for specifying the syntax of the command-line which you can use to print and specify a (non-default) printer. You can also Google for printto, see e.g. PrintTo command in the ShellExecute.
3). I have implemented an HTML control for .NET of my own, which doesn't depend on IE. You say that your HTML (and CSS I presume) are simple, so perhaps I can render it, either out of the box or with only a little extra development effort. I don't support printing, but printing is quite easy for a user control to implement. Getting me to implement that for you would cost you several hundred but, who knows, maybe it's worth it to you. It would be quite a light-weight solution, and perhaps well supported. You could email me if you want to discuss that further.
4). You might also find other controls, similar to mine, more or less famous/expensive; or other applications, e.g. OpenOffice etc etc.
5). You could consider converting the HTML (somehow) to another format (e.g. PDF) for which you have an application which gives you better support for printing.
I've had the exact same problem, and incorporated this control instead of the standard .NET WebBrowser to work around it.
This works on .NET 3.5, if not before
this.webBrowser1.ShowPrintDialog();

Fiddler/C#: search content of request/response for special phrases

this is my first visit to stackoverflow and right now I feel very comfortable with this site.
It already helped me to get the FiddlerCore embedded into MS Visual C# 2008 Express Edition.
Just needed to create a reference(Verweis) to the fiddlercore dll from Project Explorer(Projektmappenexplorer) in MS Visual C# EE. Hope this are the names for it in the english version. After this you can use Fiddler.FiddlerApplication stuff etc.
What is my task?
I want to create a small program which is able to use the FiddlerCore to check the bodies of requests/responds for special JavaScript Code.
This enables the developers to check wether their code is valid in another versions of there Browser (especially from IE 6.x to IE 8.x) or not. To be able to do so, I need to know:
How can I check the content of a requested or responded file for a String?
This must have something to do with the Text View Inspector (Fiddler), but I cannot find a possibility to access it with .net code or within Fiddler which would also help a lot already.
I should be able to finish the remaining stuff with some search by google or stackoverflow.
As this is my first time with .net languages this will be very interesting and demanding.
Take a look at this example. In the BeforeResponse callback a Fiddler.Session is passed as argument. This object has a method called GetResponseBodyAsString. As its name suggest you may try using it to get the response text. There's also a GetRequestBodyAsString method for the request.

WebBrowser control: How to overwrite URL property

This is a bit special:
I'm loading some HTML in string form into the WebBrowser control via the DocumentText property.
Now when I print the page with a PDF printer (Bullzip PDF Printer in my case) it always takes the URL as document name which is "about:blank".
Is there any way to change this to another value by either changing the URL property (it's read-only) or by changing the print behaviour to use another text rather than the URL as filename?
There are a couple of options that I am aware of though my knowledge on this subject is a bit dated.
The first is to change the computer settings in Internet Options. Regardless of whether this is done by hand or through a registry change script, it is simple for the developer, but obviously not the best approach from the deployment or compatibility angles.
The next approach is to develop a custom print template. This is not fun, but is probably the most professional approach. As much as I would love to include all of the information needed on this approach in this post, it is too much to cover. Here is a good overview and good luck Googling from there.
My experience with this involved printing from the MS WebControl component used in a .NET 1.1 Winforms application to the Web Super Goo PDF converter component. Your mileage may vary.
You can change the header and footer such that the URL property is not printed.
Try to Navigate to a URL, then cancel that via DWebBrowserEvents::BeforeNavigate

Categories

Resources