SaveFileDialog控件的用法

解决方案 »

  1.   

    SaveFileDialog saveFileDialog = new SaveFileDialog();
    if (saveFileDialog.ShowDialog() == DialogResult.OK)
    {
    string fileName = saveFileDialog.FileName;
    //这里写保存代码,fileName就是文件的路径。
    }
      

  2.   

    我的代码:
    if (this.saveFileDialog1.ShowDialog()  == DialogResult.OK )

                 //MessageBox.Show(sFileName);
                  //写入文件
                    string sFileName;
                  FileStream fs;
                  StreamWriter sw; 
                  sFileName = this.saveFileDialog1.FileName;
                  fs = new FileStream(sFileName,FileMode.Create);
                  sw = new StreamWriter(fs,System.Text.Encoding.Default); ...
                   //写入文件
                    sw.WriteLine(dr.GetValue(4).ToString() );        
                  sw.Close();
                  fs.Close();
    }
      

  3.   

     private void exportXLS_Click(object sender, EventArgs e)
            {
                SaveFileDialog fd = new SaveFileDialog();
                fd.Title = "导出Excel文件";
                fd.RestoreDirectory = true;
                fd.Filter = "Excel文件|*.xls";
                fd.FilterIndex = 1;
                if (fd.ShowDialog() == DialogResult.OK)
                {
                   this.gridView1.ExportToXls(fd.FileName);
                    XtraMessageBox.Show("文件导出成功", "导出", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
      

  4.   

    SaveFileDialog saveFileDialog = new SaveFileDialog(); 
    saveFileDialog.Filter = "Execl files (*.xls)|*.xls"; 
    saveFileDialog.FilterIndex = 0; 
    saveFileDialog.RestoreDirectory = true; 
    saveFileDialog.CreatePrompt = true; 
    saveFileDialog.Title = ""; 
    saveFileDialog.FileName =""; 
    saveFileDialog.ShowDialog(); 
    http://msdn.microsoft.com/zh-cn/library/system.windows.forms.savefiledialog(VS.80).aspx