Tip: RequestAccessEnabled programatically using the SharePoint Object Model 

I bumped into a strange problem today. It wasn't hard to solve, but worth mentioning.

To manually enable the option to request permissions to the site, you do this from Site Actions - Site Settings - Advanced Permissions - Settings - Access Request.
From that page you can specify if users should be able to request permissions to the site, and who should receive the email.

RequestAccessEnabled via code instead

No worries so far, but this time I had to do this through code upon dynamically creating a new site. This means that we need to speak to the object model in order to get things right...

When you consult MSDN, it clearly states that this property ( web.RequestAccessEnabled ) is a get/set property which you can get or set via code. However this is not the case. It's a get-only property which means that you can't really use it to enable access requests.

This is simply solved by using the somewhat similar property called RequestAccessEmail. So, if you do web.RequestAccessEmail = tobias@zimmergren.net; you're automatically enabling the request access for that site.

Now your users can simply see the "Request Permissions" link in order to submit a request to the specified email-address in order to join the site.

(Just a tip to those of you who read MSDN and tried to follow it blindly ;)

Have a good day.

 
Posted on 9-Apr-08 by Tobias Zimmergren
2 Comments  |  Trackback Url  |  Link to this post | Bookmark this post with:        
Tags:
 

Links to this post (Trackbacks/Pingbacks)

Comments

Sunday, 4 May 2008 11:28 by Rick
Awesome tip.. we have been trying to get this to work for several days now with no luck. thanks a bunch!

Tuesday, 18 Nov 2008 02:14 by Eduard
In case you are trying to set/get that property, be sure that your Outbound Server Adress is set. Otherwise you get an Exception. In case you need to verify that you can do that with following code: SPOutboundMailServiceInstance instance = currentWeb.Site.WebApplication.OutboundMailServiceInstance; if (instance != null && !string.IsNullOrEmpty(instance.Server.Address)) { currentWeb.RequestAccessEmail = ""; currentWeb.Update(); }

Name:
URL:
Email:
Comments:


MCTS WSS 3.0 (Developer and Administration/Configuration) MCTS MOSS 2007 (Developer and Administration/Configuration) MCP