I am trying to save an excel file via C#, but the file is not being saved in the location I have specified using a variable. Below is the code I have:
Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
if (xlApp == null)
{
//MessageBox.Show("Excel is not properly installed!!");
return;
}
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
if (!System.IO.File.Exists(FileName))
{
xlWorkBook = xlApp.Workbooks.Add(misValue);
}
else
{
xlWorkBook = xlApp.Workbooks.Open(FileName, 0, false, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", true, false, 0, true, 1, 0);
}
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
//Some Code
xlApp.DisplayAlerts = false;
xlWorkBook.SaveAs(FileName, Type.Missing,Type.Missing,Type.Missing,false,Type.Missing,XlSaveAsAccessMode.xlExclusive,Type.Missing,Type.Missing,Type.Missing);
xlWorkBook.Close(true, FileName, misValue);
xlApp.Application.Quit();
xlApp.Quit();
What am I doing wrong here? I am beyond frustrated that is not saving where I want it to. Any help would be appreciated