Total Productivity Solutions, Inc. Company Logo
TPS Home
.NET
IIS
Networking
Search Engine
SharePoint
Add URL

Sharepoint Products and Technologies DoesUserHavePermissions() Bug

I was working on a SharePoint WebPart to display a list of the document libraries that a user had access to.  I needed this for a proposal portal that I was working on and only certain user groups would have access to specific documents in the Windows SharePoint Services (WSS) site.  This could be used for any business really.
I created my SharePoint WebPart and was looking for a way to detect if a user had access to a document library.  I found the DoesUserHavePermission() function in the SPPermissionCollection class of the SharePoint object model.  I read the documentation to see what values were returned and as I thought it was going to be true or false.  I quickly realized that this function doesn't return a false value as the documentation says.  It will return a true value if the user has permissions to the library.  When the user doesn't have permissions to the library an AccessDeniedException is thrown that is, by default, caught by Windows SharePoint Services (WSS) and the user is prompted for their credentials.
Currently there is not a “solution” for this problem but there is a work around.
To make this work two things need to be done, the first being that the CatchAccessDeniedException property of the SPSites class is set to false.  Setting this property to false will allow the exception to pass through WSS and not cause the user to be prompted for their credentials.  The second thing to do is to catch System.UnauthorizedAccessException.
For an example of how to implement this in code see my article on creating the document library view web part: Code Example of WorkAround
Home Contact Us Site Map