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.
Comments are closed
Archived comments
Nice, that it can be set programmatically this way, but do you have any idea how to get rid of it after it has been enabled once? (So the programmatically way - by using the GUI this is not a real problem)
As mentioned the RequestAccesEnabled is a get only property, the way to work around it is to set RequestAccessEmail to "" or string empty. That way it will remove the Ask for Permissions from the Site. To disable all sites in collection I used something like this in Moss 2007:
###########################################
#
# One variable disable all AccessRequest throughout SiteCollection
# Change the name of $siteUrl.
#
#######################################
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint");
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Publishing");
$siteURL = "http://site.com/";
$site = New-Object Microsoft.SharePoint.SPSite($siteURL);
foreach($web in $site.AllWebs)
{
if ($web.RequestAccessEnabled)
{
$web.RequestAccessEmail = "";
$web.update();
write-host($web.title);
}
$web.Dispose();
}
$site.Dispose();
Thanks Niko for nice workaround.
Thank you Tobias you really saved me a lot of time searching for this information.
Thank you for reading Guitou. I'm glad it could aid you in your troubleshooting.
Cheers,
Tob.
Can we do it using Client Side object model
Hi Tobias,
Is there any way we can do it in Sharepoint 2013 On-Premises, CSOM?