Save filedialog not working

前端 未结 2 1326
一向
一向 2021-01-24 14:32

Bit of an odd one here , I\'m writing an app which gives a save file option , the save file dialog is coded up as normal

SaveFileDialog ofd = new SaveFileDialog         


        
2条回答
  •  感动是毒
    2021-01-24 15:03

    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();
             }
         }
    }
    

提交回复
热议问题