I was looking around and saw the post for using resource (how-to-create-and-use-resources-in-net) . I learned how to put a file into the resources for the project and programmatically retrieve it. But, I'm not seeing the idea of having resources, maybe? I have a tab on a form where I have a webbrowser control, but I just want to show a help document. I put the html file as a resource, but when I print out after looking up the resource, it gives me all the file's text (html tags) instead of just the name of the file, such that I could do something like
helpBrowser.Url = new Uri("file//:"+Properties.Resources.help);
I might need a different approach. Im using the control not to actually browse but just display a page, which isnt t开发者_C百科he intended use exactly.
Thanks, guys. StackOverflow is great!
WebBrowser is an unmanaged component under the hood, it doesn't know anything about .NET resources. There's a protocol for it to read unmanaged resources but you don't want to go there. Simply use the DocumentText property:
private void HelpButton_Click(object sender, EventArgs e) {
webBrowser1.DocumentText = Properties.Resources.HelpPage;
}
Beware the usual trouble with displaying off-line HTML, it won't know where to find any images you embedded in the html. If that's a deal breaker then you are better off having the files on disk. Which is the all-around better solution for large files anyway.
You can't directly access the resources as a file with managed resources. You will atually have to insert the content into the web browser control manually.
Resources are embedded within your EXE or DLL and can't be access directly by a browser. You need to retrieve the resource, save it to a temporary file, and then direct the browser to that temporary file.
精彩评论