2

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 the intended use exactly.

Thanks, guys. StackOverflow is great!

4
  • I'm curious why you're pursuing resources for this. Is there something about your project that makes you reluctant to include the html file as content? Commented Apr 7, 2011 at 16:33
  • The reason is I would want to somehow package this html file into the final build artifact, so the problem becomes how to reference the full path of the file in another controls property (url) and actually packaging html file with the executable Commented Apr 7, 2011 at 16:56
  • In that case you're stuck going with Daniel's or Robert's approach. The issue is there is no file path to reference. As Robert says, it's baked directly in to the exectuable, meaning it doesn't physically exist on its own anywhere on the filesystem and therefore can't be referenced with a file path. Commented Apr 7, 2011 at 17:14
  • I think that's what I didnt understand. Thanks! Commented Apr 7, 2011 at 19:11

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

This is the best solution for me. Thanks!
1

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.

Comments

1

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.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.