Montag, 14. Oktober 2013

file.OpenBinary() - access denied

I ran over an error, which can be confusing. I wanted to get a file in SharePoint 2010 programmatically and suddenly I received the error at file.OpenBinary(), that the access is denied. I checked all the permission and was even more confused, because everything was set correctly. I was accessing via elevated privilages and this made me wonder even more.
The solution was really simple. The path to the file was wrong. Usually I would expect a file not found error message in SharePoint, but it seems an access denied is thrown in this case.
The path was not wrong in a matter, that the library was not existing, it was more, that the path went deeper in the folder structure than there was any existing in the library.

Donnerstag, 10. Oktober 2013

Secure Store Service SharePoint 2010 GetCredentials Access denied

I had the problem, that I wanted to impersonate to SecureStoreService of SharePoint 2010 programmatically, but received an access denied at the point where the method GetCredentials is called.
This happen to me twice in different scenarios:
1. I tried to impersonate in an Elevated environment. Of course, then the used system account has to be also a member of the SecureStoreService.
2. I undid the impersonation after the code sequence and it seems having different methods calling other methods, impersonated and undid and the wrong place, when other methods tried to access.
That means, be aware which account is currently running the code and that this account is also a member of the SecureStoreService.
Try to keep the impersonation area as small as possible, to impersonation does not interfere with other impersonation-efforts.