0

I have a live webpage that will act as the output of my program.

I would like to include the source html file and have the browser navigate to that for initialization instead of putting the entire html source code into a hard coded string.

Any ideas?

3
  • what are your real intentions then for this type of request sounds a bit suspecious in nature..
    – MethodMan
    Dec 21, 2011 at 20:46
  • I am developing a messaging program. The output of the program is displayed in a webBrowser control so that I have full control over the way that the output looks. In response to this: stackoverflow.com/questions/8595125/… and stackoverflow.com/questions/8591918/… I decided that I would rather embed the html instead of putting it in as a string so that it is easier to read and modify in the future. It is not suspicious. Dec 21, 2011 at 20:50
  • Metro? WinForms? WPF? Silverlight? ASP.Net? MonoTouch?
    – SLaks
    Dec 21, 2011 at 21:00

3 Answers 3

0

Set the DocumentText property to your source string.

For better performance, set Document.DocumentElement.OuterHtml instead.
(You may need to load a dummy document first)

5
  • That's what I would like to do. I just want a way to load the source string from the html file and embed it in the project, instead of converting it to a string on my own and just putting that in as a constant. Dec 21, 2011 at 21:00
  • @NathanTornquist: Are you asking how to read an embedded resource? That's a totally separate question.
    – SLaks
    Dec 21, 2011 at 21:01
  • Note that you cannot use this approach with images.
    – SLaks
    Dec 21, 2011 at 21:01
  • I think I might be asking that. I tried doing this: support.microsoft.com/kb/319292 and I get an "Error Accessing Resources" message. Something doesn't quite work right. Dec 21, 2011 at 21:13
  • --Nevermind. I got it to work. That Microsoft resource and your answer worked perfectly. Dec 21, 2011 at 21:14
0

I suggest you to save embedded html into the temp directory and then navigate to that saved file address.

3
  • I will not have access to data outside of the program. Saving to a temp directory may not be possible depending on the server permissions of my clients. Dec 21, 2011 at 20:42
  • @NathanTornquist: It should always be possible to write to %TEMP%
    – SLaks
    Dec 21, 2011 at 20:53
  • @SLaks, I can certainly try that. It seems silly that you can't navigate to an included file though. That would be incredibly useful. Dec 21, 2011 at 20:56
0

Another way is to open your embedded file as stream and then use http://msdn.microsoft.com/en-us/library/system.windows.controls.webbrowser.navigatetostream.aspx

NavigateToStreamMethod of a webbrowser!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.