3

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");
}
abatishchev
  • 98,240
  • 88
  • 296
  • 433
Matt
  • 187
  • 1
  • 4
  • 13

3 Answers3

8

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

Unknown
  • 401
  • 2
  • 5
6

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.

Tony The Lion
  • 61,704
  • 67
  • 242
  • 415
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");
abatishchev
  • 98,240
  • 88
  • 296
  • 433