使用Process.Start在C#中打开一个文件

时间:2011-04-08 08:39:51

标签: c# .net winforms process.start

我正在编写一个程序来监视文件夹,并让您知道何时创建文件。当用户点击“确定”时,我很难打开文件。我可以就如何使Process.Start()工作提出建议,我试图让文件位置从e.Fullpath加载文本文件并在记事本中打开。

private void fileSystemWatcher1_Changed(object sender, FileSystemEventArgs e)
{
    DialogResult messageresult = MessageBox.Show("You have a Collection Form: " + e.Name);
    if (messageresult == DialogResult.OK)
        Process.Start("Notepad.exe", "e.FullPath");
}

3 个答案:

答案 0 :(得分:8)

尝试Process.Start("Notepad.exe", e.FullPath);

答案 1 :(得分:6)

Process.Start的第二个参数是一个字符串,但是您传递的是字符串类型,因此您不需要使用“它周围的标记。”

只有字符串文字(例如第一个参数)需要在它们周围加上引号。

答案 2 :(得分:3)

string notepadPath = Path.Combine(Environment.SystemDirectory, "notepad.exe");
if (File.Exists(notepadPath))
    Process.Start(notepadPath, e.FullPath);
else
    throw new Exception("Can't locate Notepad");
相关问题