3

我正在编写一个监视文件夹并让您知道何时创建文件的程序。当用户单击确定时,我正在努力打开文件。请我就如何开始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");
}
4

3 回答 3

8

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

于 2011-04-08T08:43:05.750 回答
6

Process.Start 的第二个参数是一个字符串,但是你传递的是一个字符串类型,所以你不需要在它周围使用 " 标记。

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

于 2011-04-08T08:44:52.780 回答
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");
于 2011-04-08T08:45:21.600 回答