I have a BCS connector.
In a constructor of its service class I want to access a SharePoint list.
using (var site = new SPSite("My site URL")
{
using (var web = site.RootWeb)
{
var list = web.Lists.TryGetList("My List"); //Getting value error: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))!
...
}
}
But when I try to access the list like in the code example above, Im getting the Getting value error: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))!
error.
The account I'm using for crawling is the same account I'm using myself for SharePoint administration so I'm pretty sure it has access to the list since I'm the one who created it?
What is the cause of this access denied error and how can I resolve it?
EDIT:
I trid using
SPSecurity.RunWithElevatedPrivileges(()=>{/*Here goes the code from the example above*/});
but it didn't changed a thing.
I'm still getting the same error.
However, when I tried the exact same code as in the first example in a console application on the same server it worked as expected.