Click here to Skip to main content
15,940,173 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
SaveFileDialog saveDlg = new SaveFileDialog();
saveDlg.InitialDirectory = @"C:\";
saveDlg.Filter = "Excel files (*.xls)|*.xls";
saveDlg.FilterIndex = 0;
saveDlg.RestoreDirectory = true;
saveDlg.Title = "Export Excel File To";

if (saveDlg.ShowDialog() == DialogResult.OK)
{
    try
    {
        string path = saveDlg.FileName;
        // xlWorkBook.SaveCopyAs(path);
        ExcelLibrary.DataSetHelper.CreateWorkbook("MyExcelFile.xls", ds);

        MessageBox.Show("File is Created");
    }


    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

Posted
Comments
ZurdoDev 2-Dec-14 8:36am    
What is your question?
Maciej Los 2-Dec-14 11:52am    
I can get why are you getting full file name (including path) and than you ignore it...

1 solution

Please, read my comment to the question.

Here is proper usage of SaveFileDialog[^]:
C#
{
      string fullpath = saveDlg.FileName;
      // xlWorkBook.SaveCopyAs(path);
      ExcelLibrary.DataSetHelper.CreateWorkbook(fullpath, ds);
      //File has been created
  }
 
Share this answer
 
Comments
BillWoodruff 2-Dec-14 12:33pm    
+5
Maciej Los 2-Dec-14 12:36pm    
Thank you, Bill ;)
cash10 8-Dec-14 4:13am    
Error:Object reference not set to an instance of an object.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900