Save filedialog not working

ぐ巨炮叔叔 提交于 2019-12-02 05:01:22

The SaveFileDialog class doesn't save anything, it prompts the user to choose a location and a file name to save the file. It is your job to save the file

This example extracted from the MSDN link above explains the concept

private void button1_Click(object sender, System.EventArgs e)
{
     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)
         {
             // Code to write the stream goes here.
             myStream.Close();
         }
     }
}
Stream stream;
ofd.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"  ;
     ofd.FilterIndex = 2 ;
     ofd.RestoreDirectory = true ;

if(ofd.ShowDialog() == DialogResult.OK)
     {
         if((stream = ofd.OpenFile()) != null)
         {
    //FileStream might be better for you but since i don't know what you write, this will serve as an example
             stream.Write(bytes,offset,count);
             stream.Close();
         }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!