Create a file in the userfiles folder (C#, Windows Forms)
c#, file, winforms
Solution
You can use `Environment.GetFolderPath` to get the path to the user data folder:
string fileName = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"userinfo.txt");
Look into the documentation of the Environment.SpecialFolder enum in order to find the folder that best suits your needs.
Problem
I'm trying to create a text file in my Windows Forms application. It is working fine, but it is creating the text file in the application's default location (like in folder `bin`). But I want to save that created text file in my user files folder. How can I do it? This is my code: ``` FileInfo fileusername = new FileInfo("userinfo.txt"); StreamWriter namewriter = fileusername.CreateText(); namewriter.Write(txtUsername.Text); namewriter.Close(); ```