Unable to create the excel file at particular path when the application is run from IIS. But its created when the code is debuged using visual studio 2008.Even i have tried out using absolute path and using server.mappath() function but in vain.Server throws the error : HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly. Requested URL: /Error.aspx
The code is given below:
private void CreateExcel(DataTable dt)
{
try
{
FilePath = "\\\\192.168.1.252\\GNC Reports\\TallyExport.xls";
Excel.Application oXL = new Excel.Application();
//Get a new workbook.
Excel._Workbook oWB = (Excel._Workbook)(oXL.Workbooks.Add(Type.Missing));
// *************** Sheet 1
Excel._Worksheet oSheet = (Excel._Worksheet)oWB.Sheets["Sheet1"];
oSheet.Name = "Journal";
WriteWxcel(oSheet, dt, 3);
//***************** Sheet 2
oSheet = (Excel._Worksheet)oWB.Sheets["Sheet2"];
oSheet.Name = "Payroll";
WriteWxcel(oSheet, dt, 4);
// ************* Sheet 3
oSheet = (Excel._Worksheet)oWB.Sheets["Sheet3"];
oSheet.Name = "Receipt";
WriteWxcel(oSheet, dt, 2);
//Save Excel File
oWB.SaveAs(FilePath, Excel.XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Excel.XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
oXL.Quit();
}
catch (Exception ex)
{
BussinessLayer.CMSException.Instance.HandleMe(this, ex);
}
}