About      |       Articles      |      Services      |      Software      |      Contact

Latest Free SharePoint Software

ARB Security Solutions regularly releases free SharePoint software, including WebParts, Client Applications, Framework Extensions, and other Miscellaneous Components.
The most recent freeware is:

Title: Simple SharePoint Rollup WebPart
Date Published: 10/22/2009

Previous Two Free WebPart Releases:

SecureCenter For SharePoint

By SharePoint security integrators, for SharePoint security integrators.

SharePoint Security Assurance Program™

For externally facing SharePoint deployments, security is an acutely important deployment concern. Learn how through daily security scanning, you can ensure external business users and partners that they can collaborate in confidence!

Security Assurance WebPart:



Testing Whether A User Has SPBasePermission On SPList Object

This was driving me nuts yesterday, I was looping through all sorts of crap, and all I wanted to do was conditionally display something base on the SPBasePermissions enumeration. Reason being, we have a custom menu that appends to the Site Actions menu (i.e. through the use of a feature) building out relative links to the site to a variety of lists using SubMenuTemplate and MenuItemTemplate objects. I didn't want to display on my menu lists that a SPUser didn't have specific rights to, particularly I wanted to test whether the principal had SPBasePermissions.DeleteListItems. So, I just wanted a stupid little method that took an SPList object as a parameter, then I could use it to wrap my menu outputs within an if statement to conditionally display them. This probably isn't the most optimized way that this could be written, but it works for me:

C#:
  1. private bool UserHasDeletePermission(SPList list)
  2. {
  3. try
  4. {
  5. if (((ISecurableObject)list).DoesUserHavePermissions(SPBasePermissions.DeleteListItems))
  6. {
  7. return true;
  8. }
  9. }
  10.  
  11. catch (Exception exception)
  12. {
  13. WriteLogEvent(string.Format("An Error Occured With The {name of your app} | Exception Message:{0} StackTrace: {1}", exception.Message, exception.StackTrace));
  14. }
  15.  
  16. return false;
  17. }
  18. public void WriteLogEvent(string strmessage)
  19. {
  20. EventLog comLog = new EventLog("Application");
  21. if (!EventLog.SourceExists("{name of your app}"))
  22. {
  23. EventLog.CreateEventSource("{name of your app}", "Application");
  24. }
  25. comLog.Source = "{name of your app}";
  26. comLog.WriteEntry(strmessage);
  27. }

You know what sucks? After you always write these annoying little things they make sense, and you sit there going, "well, of course it should be that way". I hadn't read about the ISecurableObject interface before, but it is pretty clutch, since it will allow you to expose the role assignments and pretty much tackle any permission manipulation with pretty much any SharePoint object type. Which is where I got stuck.

Oh well, hopefully it saves someone some time :)

  • Share/Bookmark

3 Comments »

  1. [...] Testing Whether A User Has SPBasePermission On SPList Object [...]

    Pingback by Links (8/30/2007) « Steve Pietrek’s SharePoint Stuff — August 30, 2007 @ 6:02 pm

  2. [...] This was driving me nuts yesterday, I was looping through all sorts of crap, and all I wanted to do was conditionally display something base on the SPBasePermissions enumeration. Reason being, we have a custom menu that appends to the Site Actions menu Read More……(read more) [...]

    Pingback by Blogger Loser » Blog Archive » Testing Whether A User Has SPBasePermission On SPList Object — August 31, 2007 @ 2:10 am

  3. [...] Testing Whether A User Has SPBasePermission On SPList Object [...]

    Pingback by Links (8/30/2007) « Steve Pietrek - Everything SharePoint — November 13, 2008 @ 5:39 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment