views:

211

answers:

1

I have a custom web service deployed in SharePoint, web method of this webservice expects a SharePoint docuentUri as a parameter. As it is deployed in the SharePoint environment i am done with SharePoint authentication, but the question here is that how do i check whether the user reqesting for a perticular document is authroized or not ? In other words web service method should return some unauthorized exception if the user does not have privilege to view the document ? All i have is the SharePoint documentUri to pass as an inpurt parameter.

thanks.

+1  A: 

Hi Nikhil,

Assuming your web service is deployed in the context of SharePoint in the /_vti_bin virtual directory of your SharePoint site, you can use the SharePoint object model like below to check if the calling user has specific privileges to your document. Unfortunately, the CheckPermissions call will throw an UnauthorizedException if the check fails, so it would have to be caught.

string uri = "http://localhost/Shared%20Documents/Document1.doc";  //full path to doc
using (Microsoft.SharePoint.SPSite site = new Microsoft.SharePoint.SPSite(uri))
using (Microsoft.SharePoint.SPWeb web = site.OpenWeb())
{
 Microsoft.SharePoint.SPListItem item = web.GetListItem(uri); 
 item.CheckPermissions(Microsoft.SharePoint.SPBasePermissions.OpenItems);
} 

Hope this helps,

Steve

Steve Danner