Question: I can't seem to create a new blank excel file so I can write in it with excel Interop later

```
 System.IO.FileStream fs =(System.IO.FileStream)saveFileDialog1.OpenFile();
 switch (saveFileDialog1.FilterIndex)
 {
     case 1:
         //write blank xlsx?
         break;
     case 2:
         //write blank xls?
         break;
 }
 fs.Close();
 ExportDataSetToExcel(_destinationDataSet, saveFileDialog1.FileName);

```

If I pass an empty file I got this error

> 
> Cant open file because the file format or file extension is not valid.
>  Verify that the file has not been corrupted and that the file
>  extension matches the format of the file.
> 
> 
> 

So.. How can I create an empty xls or xls file?

Answer: 
Empty Excel files are not simple empty files, since they also store some header data. One modern way of writing Excel files is to use `Open XML SDK 2.5` as indicated [here](https://msdn.microsoft.com/en-us/library/office/ff478153.aspx):

```
var spreadsheetDocument = SpreadsheetDocument.Create(filepath, SpreadsheetDocumentType.Workbook);

```

By doing so, you get a reference that allows you to write data to the Excel file.

In order to get a value for `filepath`, you can you use `SaveFileDialog` to indicate path to be used like indicated in the [documentation](https://msdn.microsoft.com/en-us/library/sfezx97z(v=vs.110).aspx):

```
var saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "Excel files|*.xlsx";
saveFileDialog1.Title = "Save an Image File";
saveFileDialog1.ShowDialog();

if(saveFileDialog1.FileName != "")
{
    // file name is available here
}

```

You can make your Excel manipulation in C# even easier by using a third party library such as [EPPlus](http://epplus.codeplex.com/).

**Disclaimer:** Above hints work only for the Excel 2007 and above formats.
I ended up doing this...

```
if (saveFileDialog1.FileName != "")
    {
      var app = new Application();
      var wb = app.Workbooks.Add();
      switch (saveFileDialog1.FilterIndex)
         {
            case 1:
               wb.SaveAs(saveFileDialog1.FileName);
               break;    
            case 2:
               wb.SaveAs(saveFileDialog1.FileName, XlFileFormat.xlExcel8);
                        break;
         }
      wb.Close();
      app.Quit();

      ExportDataSetToExcel(_destinationDataSet, saveFileDialog1.FileName);
    }

```