Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Notepad Path in VS2008

Tags:

c#

notepad

In my application, I have defined the following:

public static readonly string NOTEPAD = "%windir%\\notepad.exe";

I can type in the text value of NOTEPAD into the Run command on my Win7 machine, and Notepad will open.

However, from within my Visual Studio C# project, the Write Line routine will fire every time:

  if (!File.Exists(NOTEPAD)) {
    Console.WriteLine("File Not Found: " + NOTEPAD);
  }

Does Visual Studio not understand %windir%?

like image 426
jp2code Avatar asked Feb 27 '23 18:02

jp2code


1 Answers

Instead of expanding the variable manually as suggested by the other answers so far, you can have the Environment class do this for you just like the Run command does:

if (!File.Exists(Environment.ExpandEnvironmentVariables(NOTEPAD))) {
  Console.WriteLine("File Not Found: " + NOTEPAD);
}

See http://msdn.microsoft.com/en-us/library/system.environment.expandenvironmentvariables.aspx

like image 173
Lucero Avatar answered Mar 06 '23 18:03

Lucero