Accessing excel file in sharepoint solution

195 Views Asked by At

I am trying to run this code as SharePoint solution. When I deploy it, it gets stuck on trying to open excel file:most likely, solution does not have an access. When I try to run the same code in console application, when opening a workbook, the console app asks for username and password.

string fileName = "http://spserver/sites/dev2/Style%20Library/BookRefresh.xlsx";
var excel = new Microsoft.Office.Interop.Excel.Application();
excel.DisplayAlerts = false;
Workbook theWorkbook = excel.Workbooks.Open(fileName);

please, do you have an idea how I can get a permission to access this file in sharepoint solution? thank you

this is the error:

System.Runtime.InteropServices.COMException was unhandled by user code
  HelpLink=xlmain11.chm
  HResult=-2146827284
  Message=Microsoft Excel cannot access the file 'http://spserver/sites/dev2/Style Library/BookRefresh.xlsx'. There are several possible reasons:

• The file name or path does not exist. • The file is being used by another program. • The workbook you are trying to save has the same name as a currently open workbook.

0

There are 0 best solutions below