Cannot Write to Excel File

  • Thread starter Thread starter OldeEnglishD
  • Start date Start date
O

OldeEnglishD

Guest
I don't get it! It works just fine with C# and Winforms! What is so special about MVC?

An exception of type 'System.Runtime.InteropServices.COMException' occurred in Movies.dll but was not handled in user code

Additional information: The file could not be accessed. Try one of the following:



• Make sure the specified folder exists.

• Make sure the folder that contains the file is not read-only.

• Make sure the file name does not contain any of the following characters: < > ? [ ] : | or *

• Make sure the file/path name doesn't contain more than 218 characters.

=======================================================================

oXL = new Microsoft.Office.Interop.Excel.Application();
//oWB = oXL.Workbooks.Add(Type.Missing);

// This doesn't work either

//oWB = oXL.Workbooks.Open(System.Web.Configuration.WebConfigurationManager.AppSettings["ExcelFile"]);
//oWS = (_Worksheet)oWB.ActiveSheet;
oWB = (Microsoft.Office.Interop.Excel._Workbook)(oXL.Workbooks.Add(""));
oWS = (Microsoft.Office.Interop.Excel._Worksheet)oWB.ActiveSheet;
oWS.EnableCalculation = false;
oWS.Cells[1, 1] = "Movie";
oWS.Cells[1, 2] = "Actors";
oWS.Cells[1, 3] = "Crew";
oWS.Cells[1, 4] = "Description";
oWS.Cells[1, 5] = "Category";

//bookmark -- Write results to Excel
foreach (var lst in lstMovies)
{
oWS.Cells[intRow, 1] = ("" + lst.Item1).ToString();
oWS.Cells[intRow, 2] = ("" + lst.Item2).ToString();
oWS.Cells[intRow, 3] = ("" + lst.Item3).ToString();
oWS.Cells[intRow, 4] = ("" + lst.Item4).ToString();
oWS.Cells[intRow++, 5] = ("" + lst.Item5).ToString();
}

oWB.SaveAs(System.Web.Configuration.WebConfigurationManager.AppSettings["ExcelFile"]);

==============================================================

It blows up on the SaveAs statement above yet I am running as an administrator

System.Web.Configuration.WebConfigurationManager.AppSettings["ExcelFile"] is

<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="ExcelFile" value="C:\\Movies\\Movies.xlsx" />
</appSettings>

Continue reading...
 
Back
Top