I'm trying to use a resource (html file) located in a dll. With WinForms WebBrowser, when I navigate to the file, nothing happens, while with included AxSHDocVw.dll and SHDocVw.dll and AxWebBrowser, it works. Is the WinForms WebBrowser control somehow restricted or something? Can I make it to run res://?
See my post here: https://stackoverflow.com/a/15672462/1413201.
The basic gist is there are two types of resources in code files. You need to include a C style resource script to use the res protocol. Navigation errors are probably turned off in the WebBrowser control and therefore you don't see an error.
You can use the res protocol with IE to test if the resource is actually in the file and a C style resource editor just to double double check.
What I would assume, is that for security reasons, WinForms' WebBrowser control doesn't handle res:// links. It would make it very easy for someone to access resources which are contained within your DLLs which you may not want accessed.
If you want to implement the functionality yourself, then I'd recommend looking at the Assembly class and its use. It shouldn't be hard to parse a res:/// into your DLL path, load the assembly, search for the given resource and return that for the WebBrowser control.
Related
I am wanting to manipulate a page being loaded in a WebBrowser by adding a stylesheet on the DocumentComplete event. I'd like to do it without using an external file, if possible.
Most of the solutions I've seen involve deprecated methods or libraries such as mshtml. The MSDN says that the accepted method is to use HtmlElement myelement = mywebbrowser.Document.CreateElement(
"style"), but nothing else. Manipulation of such seems to be problematic - things like trying to set InnerHtml throws an error at runtime (ie, System.NotSupportedException: Property is not supported on this type of HtmlElement).
Given all that, what is the best/proper way to add a big chunk of CSS to a page loaded in a WebBrowser?
One of or legacy applications (WinForms), uses the WebBrowser-Control for displaying html files. The html document itself has a lot references to other files (css, js, images, etc.). All files – including the html file itself - are located in a zip file and should stay in there. So extracting the files is no option.
During a current refactoring phase we will switch the GUI to WPF and do other optimizations as well. One of this optimizations concerns the resolving of the referenced files of our html documents. Right now we use a custom protocol implementation which has a lot of Interop and other things I want to get rid of if possible.
Lately I discovered a nice new feature in WinRT. The IUriToStreamResolver interface. The interface defines just a single method – UriToStreamAsync. An implementation of that interface can be passed to NavigateToLocalStreamUri of the WebView control and handles the resolving of all resources loaded into the WebView.
Is there any way to accomplish something like this in a normal .Net WPF Application or do we have to stick to our old custom protocol approach? Has anybody experiences with that kind of scenario?
Regards
Dominik
I had simular problem few years ago, but did not found acceptable solution for IE control. But you can use Chromium Embedded Framework for Sharp or Gecko Sharp. As I remember they have such methods. Bad for me, they haven't enough methods for my purpose, but may be they acceptable for you.
Or you may just leave as is, Asynchronous Pluggable Protocol isn't so bad.
I want to write the entire contents of my application page (eg Mainpage.xml) to a file (in Isolated Storage ) How do I do it in WP7 ? are there any methods available to parse the page contents and write it to file in windows phone 7 ?
There is no built in way to do this.
However there are a couple of approaches you could try:
If the structure is static you could try and extract the resource containing this from the DLL. For future re-use it would be easier to load the page from the DLL again though.
If you're generating a page (or part of a page) at runtime (based on user input/preferences) and you want to be able to save/reload this then just save enough information to be able to recreate it. It's unlikely that XAML would be the best format for this though.
You could create this as you build the UI. Alternatively you could walk the visual tree to get details of all that is rendered. I'd recommend recording as you go so you can more easily keep track of non-default values in the rendered objects.
I have a custom control that has some embedded resources. I need to be able to reference some of the embedded material outside the control in JavaScript. So let's say I have an image file embedded in the control and I have a script outside the control that will do something with that file. How do I reference that file name outside the control?
Update: Not sure if this is even possible and I have not found any information on it. Anyone have an idea? Maybe I create functions inside the embedded JS to get access to those files?
Is this what you are looking for?? It looks like you can use the GetWebResourceURL from the ClientScriptManager class to do this.
I have used the embedded resource js file to reference the .resx file before.
(by including something like
[assembly: ScriptResource("Applications.Webs.Scripts.HelpModule.js",
"Applications.Webs.Scripts.Resources.HelpResources", "Resource.HelpResources")]
in the code behind of the page, where HelpModule.js is a embedded resource)
I was wondering if I can access the .resx when the js is a content file? I have heard "no"s so far. Does any one know if this can be done?
Thanks for your replies in advance.
If your question is whether you can use values from the .resx in the JavaScript code, the answer is "not directly". You'll have to expose the resources from the resx as JavaScript variables that are emitted with your response and parsed by the browser in order to use them in your JS.
You could fudge this a little
Use a HttpModule to parse the JS just before its sent down to the client
looking for 'Tags'.
When you encounter your Tag then replace it with the required value from the resx file...
I used a technique similar to this for localizing JS files recently...
Alternatively, you might be able to use AJAX to muddy it up a bit. If you built a small method that was designed to dip into the resx file you could asynchronously dip. If you didn't want to use all of the Microsoft AJAX compiled stuff (for whatever reason), you could use a small AJAX engine (they're everywhere) and just wire it up to a .ashx handler. That way you could dip into the compiled .resx anytime you needed to. You'd just have to be willing to accept whatever connection latency AJAX might give you.