C# write file to MyDocuments
Using class System.Environment you can get paths of special Windows folders such as Program Files, My Documents and others. The list of available values is stored in enum object Environment.SpecialFolder (Fugure 1).
The code for receiving and using of My Documents folder path is below. The program writes file in My Documents folder and reads it.
static void Main(string[] args)
{
string myDocuments = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string filename = Path.Combine(myDocuments, "helloworld.txt");
File.WriteAllText(filename, "Hello world");
string content = File.ReadAllText(filename);
Console.WriteLine(content);
}


A Hidden Visual Studio Trick: Execute Selected Code with double Ctrl+E
What do to with Zone.Identifier files after importing a WSL machine and copying data
Support for SharePoint Server 2019 ends on Tuesday, July 14, 2026