0
votes

I added the Microsoft.SharePoint.dll into a console application and have written some SharePoint code, i can see the results on the console, but when I created a Web API project and added the same code, its throwing the error. Any idea what I am missing? Does Web API support SharePoint or tweaks have to done?

Console Application: Able to get the count of alerts on the site Console project with Microsoft.SharePoint.dll

Web API Application: Getting error here... Web API project with Microsoft.SharePoint.dll

Update1: Hosted the Console and Web API app in the same server where SharePoint is installed. Null reference is for the SPWeb object.

Update2: Not all the values of SPSite and SPWeb objects are not filled with SharePoint data. Some values like SPSite Id are returned, but not all.

"Function evaluation disabled because a previous function evaluation timed out. You must continue execution to reenable function evaluation."

enter image description here

1
A few questions. Is it the web or the Alerts object that is null? How do you authenticate the API? - Eric Herlitz
The second update is irrelevant - if you try to enumerate eg. AllWebs the delay is so large the debugger times out and refuses to display the rest of the methods. That doesn't mean they are empty - Panagiotis Kanavos
Does your application pool identity have permission to this site? Why do you use the server-side SDK instead of the client-side SDK anyway? - Panagiotis Kanavos
@PanagiotisKanavos Didnt work with the client side SDK, I have few questions. 1 - How can we use Client side SDK with Web API. 2- Any issue which would come across if we use Client side SDK? - krishna

1 Answers

0
votes

Resolved it by placing SharePoint Server side code in

RunWithElevatedPrivileges

and using the same Application Pool Identity which is being used to run the SharePoint Web Application.