Can we create Excel File using File.Create?
<p>I want to create an Excel file, at specific location and specific name in c#.
Can we use <code>File.Create("Filename.xlsx")</code> for this?</p>

<p>This creates the file, but when we try to open it; it says problem in extension.</p>

<p>I have tried another way, using excelApp. But that way, it creates Excel file  default at "~Documents\Sheet1.xlsx". So i can't specify location and filename in that case.</p>

<pre><code>Excel.Application excelApp = new Excel.Application();
Excel.Workbook excelWorkBook = excelApp.Workbooks.Add(1);
</code></pre>

<p>The question is similar to - <a href="https://stackoverflow.com/questions/13320667/how-to-specify-path-and-filename-while-creating-a-excel-file-in-asp-net-using-c">Specify Path and filename while creating excel</a></p>

<p>Since i am unable to comment, i have to ask again.
I have tried the answer provided in link.</p>

<p>My code:</p>

<pre><code>    Excel.Application excelApp = new Excel.Application();
    object missing = System.Reflection.Missing.Value;
    Excel.Workbook excelWorkBook = excelApp.Workbooks.Add(missing); 

//....
        Fill excelWorkbook after creating worksheets
....//

       excelWorkBook.Save();
</code></pre>

<p>Now, as per suggestion, instead of Save, i have used SaveAs.</p>

<pre><code> excelWorkBook.SaveAs(@"E:\\MyExcelBook\\abcd.xlsx",
                        Excel.XlFileFormat.xlOpenXMLWorkbook, missing, missing,
                        false, false, Excel.XlSaveAsAccessMode.xlNoChange,
                        missing, missing, missing, missing, missing);
</code></pre>

<p>It gives me error:
*The file could not be accessed. Try one of the following:\n\n• Make sure the specified folder exists. \n• Make sure the folder that contains the file is not read-only.\n• Make sure the file name does not contain any of the following characters:  &lt;  >  ?  [  ]  :  | or  <em>\n• Make sure the file/path name doesn't contain more than 218 characters.</em></p>

<p>Please tell me where am i doing wrong?</p>