关于在 Firefox 中查看文本,我有一个非常直接的问题。我的应用程序正在生成一些我需要在 Firefox 中查看的文本。如果我保存一个 .txt 文件并在 Firefox 中打开它,浏览器的其中一个插件就能够利用该文本并执行它需要执行的操作。
我一直在通过创建一个临时文件,将文本写入其中,然后在 Firefox 中打开该文件来完成此操作。问题是,一旦它提供给 Firefox,我需要删除该文件,所以我没有数百个这样的文件。我正在使用临时文件方法,因为我找不到有关能够在浏览器的参数中仅传递一些直接文本的信息。
无论如何,这就是我现在所拥有的,您可以看到我File.Delete
实际上在 Firefox 可以访问之前删除了该文件。如果我更慢地单步执行代码,那很好。
有任何想法吗?
try
{
string fileName = Path.GetTempFileName();
FileInfo fileInfo = new FileInfo(fileName);
fileInfo.Attributes = FileAttributes.Temporary;
string writetext = "text I need in a Firefox page";
File.WriteAllText(fileName, writetext);
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "firefox.EXE";
startInfo.Arguments = fileName;
Process.Start(startInfo);
if (File.Exists(fileName))
{
File.Delete(fileName);
}
}
catch (SystemException ex)
{
MessageBox.Show("An error occured: " + ex.Message);
}