For powershell the following works:
[environment]::getfolderpath("mydocuments")
and avoiding magic strings
[Environment]::GetFolderPath([Environment+SpecialFolder]::MyDocuments)
For .NET the following holds true (ie not applicable in all windows applications):
As one answer points out, there is no Environment Variable pointing to My Documents but there is Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
(C#) for .NET.
I’m adding this answer since this question comes up when googling for C#, environment variables and my documents and Justin’s answer does not contain the line of code 🙂
Using the above mentioned line of code is the preferred way of accessing my documents in .NET 🙂
Copy paste this row for C# usage:
var directoryNameOfMyDocuments = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
Note that C# needs a capital D in MyDocuments.