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?

Nathan Tornquist
  • 6,468
  • 10
  • 47
  • 72
  • what are your real intentions then for this type of request sounds a bit suspecious in nature.. – MethodMan Dec 21 '11 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: http://stackoverflow.com/questions/8595125/javascript-timer-runs-sporadically and http://stackoverflow.com/questions/8591918/webbrowser-document-write-irregular-performance 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. – Nathan Tornquist Dec 21 '11 at 20:50
  • Metro? WinForms? WPF? Silverlight? ASP.Net? MonoTouch? – SLaks Dec 21 '11 at 21:00

3 Answers3

0

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

Elastep
  • 3,272
  • 1
  • 14
  • 16
  • 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. – Nathan Tornquist Dec 21 '11 at 20:42
  • @NathanTornquist: It should always be possible to write to `%TEMP%` – SLaks Dec 21 '11 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. – Nathan Tornquist Dec 21 '11 at 20:56
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)

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • 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. – Nathan Tornquist Dec 21 '11 at 21:00
  • @NathanTornquist: Are you asking how to read an embedded resource? That's a totally separate question. – SLaks Dec 21 '11 at 21:01
  • Note that you cannot use this approach with images. – SLaks Dec 21 '11 at 21:01
  • I think I might be asking that. I tried doing this: http://support.microsoft.com/kb/319292 and I get an "Error Accessing Resources" message. Something doesn't quite work right. – Nathan Tornquist Dec 21 '11 at 21:13
  • --Nevermind. I got it to work. That Microsoft resource and your answer worked perfectly. – Nathan Tornquist Dec 21 '11 at 21:14
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!

Elastep
  • 3,272
  • 1
  • 14
  • 16