【发布时间】:2017-07-30 03:10:23
【问题描述】:
我正在用 C# 开发一个 HTML 编辑器,您可以在其中编辑 FastColoredTextBox.dll 组件中的代码。您将在 MenuStrip 中有一个名为“在浏览器中预览”的选项,并且会有一个名为“Chrome”和“Iexplore”等的下拉项目。我想要它而不是保存文件,我希望它在临时文件夹并预览它。在我们再次修改代码后,文件将在我们再次预览时更新。这是我到目前为止所拥有的:
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);
}
你是如何做到这一点的?
【问题讨论】:
-
问:当你尝试这段代码时会发生什么? TempSite.html 是否被写入?可以在浏览器中手动查看吗?你能以编程方式启动 Chome(或 IE 或 FF)吗?如果没有,当你尝试时会发生什么?
-
它保存并工作,但它不会自我更新。所以当我第二次预览它时,它会显示上一个。
-
固定代码块
-
可能是缓存问题?如果chrome打开后按F5显示正确的内容吗? (writer.Dispose(); 是多余的顺便说一句)
-
在这种情况下使用缓存启动 chrome:Open an url in Chrome without using the cache via command line