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 at zimmergren dot 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.