简体   繁体   中英

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

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

资源视图

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...

 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM