Reputation: 3292
Suppose I have a folder named "Games".
When I use this code it will save it in the debug folder.
FileStream outputFileStream = new FileStream("Games.txt", FileMode.Append, FileAccess.Write);
StreamWriter writer = new StreamWriter(outputFileStream);
writer.WriteLine(textBox1.Text);
writer.Close();
outputFileStream.Close();
I would like to save it somewhere inside the Games folder instead. How would I do that?
Upvotes: 0
Views: 3490
Reputation: 95
Just pointing the first argument with your path file. Let's say, you want to save into:
"C:\Another Folder\Games.txt".
You could try this code:
string pathFile = @"c:\Another Folder\Games.txt";
FileStream outputFileStream = new FileStream(pathFile, FileMode.Append, FileAccess.Write);
Make sure you have "Another Folder" in drive C. Thanks.
Upvotes: 1
Reputation: 395
Instead of simply putting the filename - "Games.txt"
you can append it to a folder inside your working directory - "Games\\Games.txt"
,
or an absolute filename path (not recommended) - "C:\\Games\\Games.txt"
Upvotes: 2
Reputation: 2427
You can provide the absolute or relative path along with the filename as follows...
FileStream outputFileStream = new FileStream("C:\Games\Games.txt", FileMode.Append, FileAccess.Write);
or
FileStream outputFileStream = new FileStream(@"..\Games.txt", FileMode.Append, FileAccess.Write);
Good Luck!
Upvotes: 4