Reputation: 187
I am writing a program that monitors a folder and lets you know when a file is created. I'm struggling to open the file when the user clicks ok. Please could I have advice on how to get the Process.Start()
to work, i'm trying to get the file location to load a text file from e.Fullpath
and open in Notepad.
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");
}
Upvotes: 3
Views: 2950
Reputation: 100348
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");
Upvotes: 3
Reputation: 63310
The second parameter of Process.Start is a string, but you are passing a string type, so you do not need to use the " marks around it.
Only string literals such as your first argument require quotation marks around them.
Upvotes: 6