How to use SaveFileDialog to save text files?




This code sample shows how to save a textfile using SaveFileDialog


Stream myStream ;
SaveFileDialog saveFileDialog1 = new SaveFileDialog();

saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" ;
saveFileDialog1.FilterIndex = 2 ;
saveFileDialog1.RestoreDirectory = true ;

if(saveFileDialog1.ShowDialog() == DialogResult.OK)
{
if((myStream = saveFileDialog1.OpenFile()) != null)
{
StreamWriter wText =new StreamWriter(myStream);

wText.Write(" your text");

myStream.Close();
}
}


Comments

Author: pieter18 Aug 2009 Member Level: Bronze   Points : 1

Just remember to Flush and close your WText object.... otherwise nothing gets written :)



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: