简体   繁体   中英

How do you save and preview an HTML file from temp folder?

I'm developing an HTML editor in C# where you can edit your code in the FastColoredTextBox.dll component. You will have this option in the MenuStrip called "Preview in browser" and there will be a drop down item called "Chrome" and "Iexplore" etc. I want it instead of saving the file, i want it to make a file in the Temp folder and preview it. and after we've modified the code again, the file will update as we preview it again. This is what i have so far:

string location = null;
string sourcecode = FastColoredTextBox1.Text;
location = System.IO.Path.GetTempPath() + "\\TempSite.html";

using (StreamWriter writer = new StreamWriter(location, true))
{
    writer.Write(sourcecode);
    writer.Dispose();
}
try
{
    System.Diagnostics.Process.Start("chrome.exe", location);
}
catch (Exception ex)
{
    Interaction.MsgBox(ex.Message);
}

How do you achieve this?

Q: How do you save and preview an HTML file from temp folder?

A: You're already doing precisely that :)

Q: Why does my browser keep re-displaying the original image?

A: Because your browser is reading the html from cache.

SOLUTION:

Give your new file a different name. For example:

location = System.IO.Path.GetTempPath() + Path.GetTempFileName() + ".html";

... OR ...

location = Path.GetTempPath() + Guid.NewGuid().ToString()  + ".html";

You can also simply hit <F5> to refresh, <Ctl-Shift-Del> to clear cache, or disable cache in your browser.

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