I want to save a txt file in a folder in AppData.
Fist how can i make a folder in AppData. ""Environment.SpecialFolder.ApplicationData" I know that this exist, but how to use it now.

when the folder is ready, how to save something in it. I'm using streamwiter.

thanks in advance.

Edited 4 Years Ago by superjj: n/a

Stream writer I believe allows you to write to a specified path, however whether or not that folder requires administrator permissions I have no idea.


To save your txt file in a folder first create a folder using c# or just by adding folder ..then you use savedialogue control and stream writer to save in that location .

here comes the code.

private void button1_Click(object sender, EventArgs e)
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                path=  saveFileDialog1.FileName;
                textBox1.Text = path;

        private void button2_Click(object sender, EventArgs e)
            System.IO.StreamWriter w = new System.IO.StreamWriter(saveFileDialog1.FileName);
            //System.IO.StreamReader r = new System.IO.StreamReader(saveFileDialog1.FileName);


Edited 4 Years Ago by kamilacbe: n/a

To do this see this code which 
// this contains my TempDocumentFolder inside my path .
DirectoryInfo _Directory = new DirectoryInfo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "TempDocuments"));

//when you load the form first check the _Directory path it is valid or it contains any file like 
		foreach (FileInfo file in _Directory.GetFiles("pe_*.pdf")) // it checks only for .pdf file for me
			//do whtever you want to do.
	catch(Exception ex1)
		// if folder is not there then it will create a folder inside a AppData Folder
	// After you get the folder save data inside this folder.
This question has already been answered. Start a new discussion instead.