Introduction
In SharePoint whenever user tries to access a site which he is not authorized to then he gets redirected to Access Denied page. In SharePoint 2010 they have introduced a feature where we can request an access for Site and that access request will get sent to an email address configured at Access Requests and Invitation page.
Solution
Find below code snippet which you can use to update email address at Access Requests and Invitation page.
The below method uses three parameter as shown:
- Email address to update : String of email address where you wish to send access request.
- web object : SPWeb Object
- IsTopSuite : Boolean value to identify if the site is top site. True if site is Top level Site collection else false.
-
-
-
-
-
-
- private void UpdateAccessRequestSettings(string emailAddress, SPWeb rootWeb, bool IsTopSite)
- {
- rootWeb.AllowUnsafeUpdates = true;
- try
- {
- if (IsTopSite == true)
- {
- if (rootWeb.RequestAccessEnabled == true)
- {
- rootWeb.RequestAccessEmail = emailAddress;
- rootWeb.Update();
- }
- }
- else
- {
- if (!siteDirList.InheritSitePermissions)
- {
- if (rootWeb.RequestAccessEnabled == true)
- {
- rootWeb.RequestAccessEmail = emailAddress;
- rootWeb.Update();
- }
- }
- }
- }
- catch (Exception ex)
- {
-
- }
- finally
- {
- rootWeb.AllowUnsafeUpdates = false;
- }
- }
This is how you need to call a method :
We can do the same thing with PowerShell as well. To do that please find my another blog at http://www.c-sharpcorner.com/code/226/powershell-script-to-update-access-request-settings-email-a.aspx
Happy SharePointing !!