I have a functionality wherein I write an excel file in a folder in application's solution and read it from there and allow save . It is working fine in local but after deploying in the server it is unable to write and this throws error on read operation saying that the file could not be found.
Please refer to the code below.
Microsoft.Office.Interop.Excel.Workbook workbook;
Microsoft.Office.Interop.Excel.Worksheet NwSheet;
appExl = new Microsoft.Office.Interop.Excel.Application();
string serverPath = Server.MapPath(".");
string filenameToLoad = serverPath + "\\Page1Reports\\" + Session["UserAccentureID"].ToString() + ".xls";
FileStream fileStream = new FileStream(filenameToLoad, FileMode.Open, FileAccess.ReadWrite, FileShare.Read);
fileStream.Write(result, 0, result.Length);
fileStream.Close();
//some more manipulation
workbook.Save();
workbook.Close();
appExl.Quit();
System.IO.FileInfo file = new System.IO.FileInfo(filenameToLoad);
if (file.Exists)
{
Response.Clear();
Response.ClearHeaders();
Response.Charset = "";
Response.ContentType = "Application/vnd.xls";
Response.AddHeader("content-disposition", "attachment;filename=Page1SLScoreCardReport.xls");
Response.AddHeader("Cache-Control", "max-age=0");
Response.WriteFile(file.FullName);
}
Please let me know what could be the issue?