Hello,
I have following code.
SPWeb web = Site.OpenWeb();
string workbookPath = web.Url + "/" + filePath + excelName; //
http://mstcsps:2374/Shared%20Documents/EPS_LM_LeaveDashboard/TeamCalendar.xlsx
ExcelService proxy = new ExcelService();
proxy.Credentials = new System.Net.NetworkCredential(@"Litware\sanchezm", @"pass@word1"); //Sanchezm has full permission on the list.
Status[] wsStatus;
DataRow newRow;
string sessionID = proxy.OpenWorkbook(workbookPath, "en-US", "en-US", out wsStatus); //Exception occurs in this line
// this function will take a RangeName
string sheetName = "Sheet1";
string namedRange = "TotalProject";
object[] returnData = proxy.GetRangeA1(sessionID, sheetName, namedRange, false, out wsStatus);
System.Data.DataTable contractData = new System.Data.DataTable("Total Project");
//DataColumn compName = contractData.Columns.Add("Project", Type.GetType("System.String"));
//DataColumn contractTotal = contractData.Columns.Add("Total Project", Type.GetType("System.String"));
for (int i = 1; i < returnData.Length; i++)
{
newRow = contractData.NewRow();
newRow["Project"] = ((object[])(returnData[i]))[0].ToString();
newRow["Total Project"] = "$" + ((object[])(returnData[i]))[1].ToString() + ".00";
contractData.Rows.Add(newRow);
}
LeaveSchedule leaveSchedule = new LeaveSchedule();
leaveSchedule.LeaveDate = (DateTime)contractData.DataSet.Tables[0].Rows[0][0];
leaveSchedule.LeaveTypeCode = (string)contractData.DataSet.Tables[0].Rows[0][1];
Its throwing exception while calling OpenWorkbook method.
Exception :
Microsoft.Office.Excel.Server.WebServices.ExcelServerApiException: You do not have permissions to open this file.
at Microsoft.Office.Excel.Server.WebServices.ApiShared.ExecuteServerSessionMethod(Boolean hasSessionId, String sessionId, CoreServerSessionMethod coreWebMethod, String name)
at Microsoft.Office.Excel.Server.WebServices.ExcelService.OpenWorkbookInternal(String workbookPath, Boolean editingMode, String uiCultureName, String dataCultureName, Boolean newWorkbook, Status[]& status)
at Microsoft.Office.Excel.Server.WebServices.ExcelService.OpenWorkbook(String workbookPath, String uiCultureName, String dataCultureName, Status[]& status)
I tried following things :
1) During debug the value of workbookPath variable I copied and access through browser, its ask for save and open excel file. So path of excel file is right.
1) SP2010 Central Admin->Manage Service Application->Excel Services Application->Global Setting
In Security Section : File Access Method : Select Process Account option. Click ok.
2) Manage Service Application->Excel Services Application->Trusted File Location->Add Trusted File Location
Location Section : Address : Give documented library path. (e.g.
http://mstcsps:2374/Shared%20Documents/)
Location Section : Trust Children : Tick for true
External Data Section : Allow External Data : Select Trusted Data Connection libraries and embedded.