Death Spirit

I'm trying to load an MHT file to a WebBrowser control from a stream. If I use the Navigate method, there's no problem. However, if I use the DocumentStream property it doesn't load correctly.

Is there any way to load it directly from a stream, without saving a temp file on disk

I tried:

WebBrowser1.DocumentText = global::TestProject.MyResourceFile.MHTFileName;

But it's print the content of the file as if I opened it in Notepad

Thanks in advance for any help given.



Re: Windows Forms General Load MHT files open as stream/string in WebBrowser contol

OmegaMan

Why is the alternate method so important





Re: Windows Forms General Load MHT files open as stream/string in WebBrowser contol

Death Spirit

There is a requirement: application must be in one file. Without sepparate and temporary files





Re: Windows Forms General Load MHT files open as stream/string in WebBrowser contol

BinaryCoder

For the "one file" requirement, you probably want to add the mht to your executable as a resource. This can be done by viewing the project's properties on the Resources tab. Click Add Resource, Add Existing File. Choose the file. After doing this, I would recommend changing the FileType on the Properties window to Binary.

You could now use System.IO.Path.GetTempFileName and System.IO.File.WriteAllBytes(tempFileName,

Properties.Resources.MyResourceName) to write it to a temporary file. Then use the WebBrowser.Navigate method on that temporary file.

If you really do not want to write the temp file, I think the only alternative is to implement a "temporary protocol handler" (i.e., a special prefix such as custom:// instead of http://). This is entirely COM interop and involves the IInternetSession::RegisterNameSpace method. It requires you provide classes implementing the IInternetProtocol and IInternetProtocolRoot interfaces. This may well be too much work for your scenario.