// 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\";
}
Originally when I wrote the above code, I was under the impression that we could create a directory in C:\
to write to, but from what I've been told, the only location they have acces to is the My Documents
directory.
So, I know I can retrieve the local Environment.SpecialFolder
with:
string path = System.Environment.GetFolderPath(Environment.SpecialFolder.Personal);
The problem is how to retrieve from the client machine. I thought about retrieving the path from the server and prepending \\tsclient\
(and removing the :
from C:
etc.), but then if the My Documents
directory isn't the same on the client as (V:
instead of D:
, for example), then I would get an Access Denied
when I try to write to the location.
Is there a way to that I can specify a string similar to CMD where you can use %USERPROFILE%/My Documents
, but with tsclient
?
Edit: I found that I can use Environment.ExpandEnvironmentalVariables()
to change the %USERPROFILE%\My Documents
to an absolute path.
string MyDocumentsLocation = Environment.ExpandEnvironmentVariables(@"%USERPROFILE%\My Documents");