Hi

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.

Recommended Answers

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.

Jump to Post

hi..

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)
        { …
Jump to Post

All 5 Replies

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.

There is nobody who can help me please

hi..

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)
        {
            saveFileDialog1.ShowDialog();
            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);
            w.Close();
            //System.IO.StreamReader r = new System.IO.StreamReader(saveFileDialog1.FileName);

        }
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 
 try
	{
		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)
	{
		System.Diagnostics.Debug.WriteLine(ex1.ToString());
		// if folder is not there then it will create a folder inside a AppData Folder
		System.IO.Directory.CreateDirectory(_Directory.ToString());
	}
	
	// After you get the folder save data inside this folder.

thanks pritesh2010. it is a good answer.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.