Saving a string to a file
Hey
I hope somebody can help. I am trying to save a string to a text file.
I am able to creat a file but I dont know how to put the context of the string down to the file. Hope somebody can help.
Creating the save file.
SaveFileDialog saveCdb = new SaveFileDialog();
saveCdb.Title = "Save Database configuration";
saveCdb.InitialDirectory = @"c:\";
saveCdb.Filter = "All files (*.*)|*.*|All files (*.*)|*.*";
saveCdb.FilterIndex = 2;
saveCdb.RestoreDirectory = true;
if (saveCdb.ShowDialog() == DialogResult.OK)
{
saveCdb.FileName= dbtxt.Text;
}
With kind regards R.F
Rasmus FlotiinPosted Mar 8, 2007, 10:24 AM
Thank you got it work now
Mike GoldPosted Mar 7, 2007, 6:38 PM
Use the SaveFileDialog to get the filename.
Use the StreamWriter class to create the file and output your context.
string myContext = "To code or not to code that is the...";
StreamWriter sw = new StreamWriter(saveCdb.FileName);
sw.Write(myContext);
sw.Close(); // don't forget to close the stream
-Mike G.