title: c# open file, path starting with %userprofile%
body: <p>I have a simple problem. I have a path to a file in user directory that looks like this: </p>
  
  <pre><code>%USERPROFILE%\AppData\Local\MyProg\settings.file
  </code></pre>
  
  <p>When I try to open it as a file </p>
  
  <pre><code>ostream = new FileStream(fileName, FileMode.Open);
  </code></pre>
  
  <p>It spits error because it tries to add <code>%userprofile%</code> to the current directory, so it becomes:</p>
  
  <pre><code>C:\Program Files\MyProg\%USERPROFILE%\AppData\Local\MyProg\settings.file
  </code></pre>
  
  <p>How do I make it recognise that a path starting with <code>%USERPROFILE%</code> is an absolute, not a relative path?</p>
  
  <p>PS: I cannot use</p>
  
  <pre><code>Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
  </code></pre>
  
  <p>Because I need to just open the file by its name. User specifies the name. If user specifies "settings.file", I need to open a file relative to program dir, if user specifies a path starting with <code>%USERPROFILE%</code> or some other thing that converts to C:\something, I need to open it as well!</p>