title: How to retrieve the path to a client machine Special Folders running RemoteApp as a filepath string?
body: <pre><code>// Set default workspace directory
  string initialDirectoryString = @"C:\work\";
  // Check if remote session, and get the local drive location
  if(System.Windows.Forms.SystemInformation.TerminalServerSession) {
      initialDirectoryString = @"\\tsclient\C\work\";
  }
  </code></pre>
  
  <p>Originally when I wrote the above code, I was under the impression that we could create a directory in <code>C:\</code> to write to, but from what I've been told, the only location they have acces to is the <code>My Documents</code> directory.</p>
  
  <p>So, I know I can retrieve the local <code>Environment.SpecialFolder</code> with:</p>
  
  <pre><code>string path = System.Environment.GetFolderPath(Environment.SpecialFolder.Personal);
  </code></pre>
  
  <p>The problem is how to retrieve from the client machine. I thought about retrieving the path from the server and prepending <code>\\tsclient\</code> (and removing the <code>:</code> from <code>C:</code> etc.), but then if the <code>My Documents</code> directory isn't the same on the client as (<code>V:</code> instead of <code>D:</code>, for example), then I would get an <code>Access Denied</code> when I try to write to the location.</p>
  
  <p>Is there a way to that I can specify a string similar to CMD where you can use <code>%USERPROFILE%/My Documents</code>, but with <code>tsclient</code>?</p>
  
  <p>Edit: I found that I can use <code>Environment.ExpandEnvironmentalVariables()</code> to change the <code>%USERPROFILE%\My Documents</code> to an absolute path.</p>
  
  <pre><code>string MyDocumentsLocation = Environment.ExpandEnvironmentVariables(@"%USERPROFILE%\My Documents");
  </code></pre>