Murlex
Murlex

Reputation: 239

opening an embedded html in an external browser in C#

Is it possible to embed an html as a resource and launch it using an external browser in C#? I don't want to use a webbrowser control just for this html in the project. It is a simple help file, if possible, I would like to embed as a resource, so that I can have a single EXE to deal with.

thanks

Upvotes: 2

Views: 1868

Answers (2)

code4life
code4life

Reputation: 15794

Drag and drop the resource html file into your Resources tab, like this:

Resources View

Then use the following code:

var txt = Properties.Resources.sample;
var fileName = Path.ChangeExtension(Path.GetTempFileName(), ".html");

var fs = File.CreateText(fileName);
fs.Write(txt);
fs.Flush();
fs.Close();

Process.Start(fileName);

That's about it...

Upvotes: 5

Micah Armantrout
Micah Armantrout

Reputation: 6971

 public void ExtractFileFromResources(String filename, String location)
        {
          //  Assembly assembly = Assembly.GetExecutingAssembly();
            System.Reflection.Assembly a =  System.Reflection.Assembly.GetExecutingAssembly();
                        Stream resFilestream = a.GetManifestResourceStream(filename);
            if (resFilestream != null)
            {
                 BinaryReader br = new BinaryReader(resFilestream);
                 FileStream fs = new FileStream(location, FileMode.Create); 
                 BinaryWriter bw = new BinaryWriter(fs);
                 byte[] ba = new byte[resFilestream.Length];
                resFilestream.Read(ba, 0, ba.Length);
              bw.Write(ba);
            br.Close();
            bw.Close();
            resFilestream.Close();
        }

    }

 string path = Path.Combine(System.IO.Path.GetTempPath() + "\file.html");

 ExtractFileFromResources("file.html", path);


 Process.Start(path);

Upvotes: 1

Related Questions