Matt
Matt

Reputation: 187

Open a file in C# using Process.Start

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

Answers (3)

abatishchev
abatishchev

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

Tony The Lion
Tony The Lion

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

Unknown
Unknown

Reputation: 411

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

Upvotes: 8

Related Questions