Hi there folks,

I have Visual C# Project- Windows Application , It has a Webbrowser Control , and I intend to load a local HTML file with images into it.

I want to embed the embed the html file and image files as resources. So I did. While using the DocumentText property of the Webbrowser Control I am able to load the HTML resource in the webbrowser control , the Image obviously isn't showing up , as the HTML file had image source as the local file path.

What I am looking for is, how do I get the embedded image to show up in the webbrowser control , when it loads the HTML file?

I googled some , and quite a lot of folks are saying to use the "res://ApplicationName.exe/SomeImage.png" in the src attribute. But obviously this is incorrect and doesn't work.

Can you help ?
thanks
miniGweek

Extract your embedded resources to a temp directory and point the web browser to the temp dir:

private void button3_Click(object sender, EventArgs e)
    {
      string tempDir = System.IO.Path.Combine(System.IO.Path.GetTempPath(), Guid.NewGuid().ToString());
      System.IO.Directory.CreateDirectory(tempDir);
      //Extract your resources --- dont forget to delete the files when you are done!
    }
commented: Thanks for concise input. +3

Thanks Sknake,
That works

So there is no way of directly accessing the resources ? Like it can be done for embedded win32 resources. I use Resource Hacker to insert resources inside the exe and then use the "res://" protocol to access the resources from the html page. Is there a downside to doing this ?

I am wondering because, suppose my program runs from a read only environment, then extracting to a temp folder will fail.

Not having access to a temp directory breaks a lot of applications and installers. That being said if you run it to that situation the person administering the machine should know how to fix it as it should be a very common problem.

I wouldn't worry about it.

Thanks for answering that sknake,

Now I need to know if there's a down side to using Resource Hacker and adding them as unmanaged win32 resources ? 1 downside I can think off is that using the same resource hacker, people could get my resource files from inside the exe. hmm I need to read up more and more on assemblies and resource management. Its still unclear ...drat.

thanks much.

The resources can still be extracted. If you want to provide another added layer of security you could encrypt all of your data files then embed the encrypted data files. When you want to present the files to the user you would decrypt them and extract the files to the temp directory. At some point the content is going to exist plaintext so it adds another layer but it is still possible to get around.

They can also use the .NET Reflector to hack your encryption code, but again, it adds another layer. I had a post similar to this one:
http://www.daniweb.com/forums/post1042705.html#post1042705

Now if I were in your situation (knowing only what has been said on this thread) I would encrypt the files then embed them, and that is about as much security as I would provide.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.