2

I try to tell you my problem. with ClosedXML i have SaveAs() method, but when i use SaveAs(string name), it saves my excel document to some strange folder with some strange path. so i've decide to use savefiledialog to give user posibility to select folder and name for document. how can i use savefiledialog with closedXML?

SaveAs() also have SaveAs(Path path). Can i use it?

Akash KC
  • 16,057
  • 6
  • 39
  • 59
Viaches
  • 143
  • 1
  • 16
  • Does `SaveAs()` have any overloads for you to add a path? – Garrett Fogerlie Aug 10 '12 at 09:49
  • Yes, it have two overloads - SaveAs(string name) and SaveAs(Path path) – Viaches Aug 10 '12 at 09:51
  • I don't know for sure, however my guess would be that you could do something like `string path = saveFileDialog.Path` after the user selects the path then use the `SaveAs(name, path)` or however `SaveAs` overloads. It's just a guess though. – Garrett Fogerlie Aug 10 '12 at 09:54

2 Answers2

6

The "strange" folder is the folder your application is running from (since you're not specifying a path).

If you want you can use the SaveFileDialog to get the path and pass it to the SaveAs method.

    var saveFileDialog = new SaveFileDialog
                             {
                                 Filter = "Excel files|*.xlsx", 
                                 Title = "Save an Excel File"
                             };

    saveFileDialog.ShowDialog();

    if (!String.IsNullOrWhiteSpace(saveFileDialog.FileName))
        workbook.SaveAs(saveFileDialog.FileName);
Manuel
  • 10,869
  • 14
  • 55
  • 86
  • 3
    Btw, strange path for strange folder is C:\Windows\System32\inetsrv and it's not a folder my application is running from) – Viaches Aug 16 '12 at 07:39
0
var saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "Excel files|*.xlsx";

//serialVal is name of a variable, not necessary at all if you don't need a specific file name

saveFileDialog.FileName = serialVal; 
if (saveFileDialog.ShowDialog() == true)
{
    workbook.SaveAs(saveFileDialog.FileName);
    workbook.Dispose();
    return;
}
kiner_shah
  • 3,939
  • 7
  • 23
  • 37
fra
  • 1