DoesUserHavePermissions

on August 7, 2006

There is a kind of ownership problem related to the DoesUserHavePermissions method with Sharepoint.

Note that this problem occurs when you are using impersonnation.

To fix that problem, the user performing the execution of the method, needs to be the same as the one who created the Parent Object. For this reason, This Method use the List object received in param and recreate the Parent object to get the ownership. And it works perfectly.

public bool UserCanViewListItems(SPList list) 
{  
bool res = true;  
SPWeb myweb = null;  
SPSite mysite = null;  
try  {          
mysite = new SPSite(list.ParentWeb.Url);             
myweb = mysite.OpenWeb();          
list = myweb.Lists[list.Title];         
list.Permissions.DoesUserHavePermissions(SPRights.ViewListItems); 
}  catch(Exception)  
{   res = false;  
}
  finally  
{   
if(myweb!=null)             
myweb.Dispose();   
if(mysite!=null)    
mysite.Dispose();  
}  
return res; 
} 

0 comments:

ShareThis