title: %AllUsersProfile%(%PROGRAMDATA%) gives a repetitive file path
body: <p>I have an application written in C#, and I am seeking to write some information to the hidden ProgramData in order to access the same connection string from both the application's front end and back end.</p>
  
  <p>I am accessing the directory using path variables as follows:</p>
  
  <pre><code>private bool ProgramDataWriteFile(string contentToWrite)
          {
              try
              {
  
                  string strProgramDataPath = "%PROGRAMDATA%";
                  string directoryPath = Environment.ExpandEnvironmentVariables(strProgramDataPath) + "\\MyApp\\";
                  string path = Environment.ExpandEnvironmentVariables(strProgramDataPath)+"\\MyApp\\ConnectionInfo.txt";
  
                  if (Directory.Exists(directoryPath))
                  {
                      System.IO.StreamWriter file = new System.IO.StreamWriter(path);
                      file.Write(contentToWrite);
                      file.Close();
                  }
                  else
                  {
                      Directory.CreateDirectory(directoryPath);
                      System.IO.StreamWriter file = new System.IO.StreamWriter(path);
                      file.Write(contentToWrite);
                      file.Close();
                  }
  
                  return true;
              }
              catch (Exception e)
              {
              }
              return false;
          }
  </code></pre>
  
  <p>This seems to work correctly. However, my question is, when I used this path variable: <code>%AllUsersProfile%(%PROGRAMDATA%)</code> 
  instead, it expanded into an illegal(and redundant) file path : <code>C:\ProgramData(C:\ProgramData)\</code>
  However, I thought that the latter path variable was the correct full name. Was I just using it incorrectly? I need to ensure that this connection info will be accessible to all users, will just using <code>%PROGRAMDATA%</code> allow that? I am using Windows 7 in case that is relevant.</p>