I am making an application to export the result of a sql query to Excel. After the file created the time I'm going to open it it gives a corrupted file error.
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "Execl files (*.xls)|*.xls";
sfd.FileName = "teste";
if (sfd.ShowDialog() == DialogResult.OK)
{
Stream s = File.Open(sfd.FileName, FileMode.CreateNew);
xlApp.DisplayAlerts = false;
xlWorkBook.SaveAs(s, Microsoft.Office.Interop.Excel.XlFileFormat.xlExcel12,
Missing.Value, Missing.Value, false, false,
Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange,
Microsoft.Office.Interop.Excel.XlSaveConflictResolution.xlUserResolution,
true, Missing.Value, Missing.Value, Missing.Value);
xlWorkBook.Close(true, misValue, misValue);
}