Reputation: 93
I want to open an included html file in the Resources directory, but it seems like my path is wrong or I am making some other mistake.
I am currently in a form class and I want to open the file if the user presses the button F1.
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = "f1.html";
proc.Start();
Upvotes: 0
Views: 99
Reputation: 13960
If you want to get some embedded resource, you need to call
ResourceManager.GetStream
http://msdn.microsoft.com/en-us/library/zxee5096.aspx
It will return a memory stream. Read the memory stream to a byte array and write the byte array to some temp location and then invoke
Process.Start()
using the path of the temp file as argument.
Here is a sample code:
public class Class1{
public static void Main(string[] args){
FileStream stream = null;
string fullTempPath = null;
try{
byte[] page = Resources.HTMLPage1;
fullTempPath = Path.GetTempPath() + Guid.NewGuid() + ".html";
stream = new FileStream(fullTempPath, FileMode.Create, FileAccess.Write, FileShare.Read);
stream.Write(page, 0, page.Length);
stream.Flush(true);
stream.Close();
Process proc = new Process{StartInfo ={FileName = fullTempPath}};
proc.Start();
}
finally{
if (stream != null){
stream.Dispose();
}
}
}
}
Upvotes: 1
Reputation: 610
Use this code to open an html file using the default browser
string filename = Environment.CurrentDirectory + System.IO.Path.DirectorySeparatorChar + "f1.html";
System.Diagnostics.Process.Start(filename);
Upvotes: 0