Set request access email address through CSOM
-
10-12-2019 - |
Question
In the server side object model it's possible to set the request access email address through the property SPWeb.RequestAccessEmail
(MSDN).
Since we are moving our SharePoint tenant to Office365 I'm looking for a way to set this value. I know it's possible to do so manually in the UI (Site Settings > Site Permissions > Access Request Settings) but since we have some self-service site creation, it's not possible to change it manually each time a web has been created.
Unfortunately there is no property Web.RequestAccessEmail
in the client side object model.
Is there a way to set this email address through the property bag (aka Web.AllProperties["__SecretKey"]
), a web service (_vti_bin
, etc.) or any other workaround?
Any help is highly appreciated!
Solution
In the newest release of the "SharePoint Online Management Shell" (v16.0.4630.1200) the included Microsoft.SharePoint.Client.dll
adds the property RequestAccessEmail
to the Web
class.
Download: https://www.microsoft.com/en-us/download/details.aspx?id=35588
You may use this DLL until the NuGet-Package is released.
EDIT: Since version 16.1.4727.1200
of the Microsoft.SharePointOnline.CSOM
NuGet-Package the RequestAccessEmail
property is supported.
OTHER TIPS
Unfortunately this property is not accessible via CSOM
.
How to retrieve all available properties for Web client object:
var allProperties = clientContext.Web.AllProperties;
clientContext.Load(allProperties);
clientContext.ExecuteQuery();
This is possible but in my opinion a hack. I wrote an article to discuss if this is a valid way to do it - Manipulating SharePoint UI over an IFrame to add missing clientside Features
Here's the Code:
//quite dirty hack but at this point the only possibility to set the AccessRequest mail via clientside
function setAccessRequest(mail) {
var iframe = document.createElement('iframe');
//set the setrqacc.aspx link
var setrqaccUrl = _spPageContextInfo.webAbsoluteUrl + '/_layouts/15/setrqacc.aspx?type=web';
//create setrqacc.aspx hidden iframe
iframe.setAttribute('src', setrqaccUrl);
iframe.setAttribute('style', 'display:none');
iframe.onload = function () {
//this will fire 2 times - the first time when its initially loaded. the second after the changes were applied (page is reloaded (postback) after the submitbutton is triggered)
var $iframeInput = $('input[id*="_txtEmail"]', $(iframe).contents());
if ($iframeInput.length) {
//initial load - apply settings
$iframeInput.val(mail);
//gets iframeInput's parent so the current input can be placed inside
var $iframeBtn = $('input[id*="_btnSubmit"]', $(iframe).contents());
//trigger the post
$iframeBtn.trigger('click');
} else {
//second load - do callback
callback('AccessRequest');
}
};
document.body.appendChild(iframe);
}
It should be wrapped in a waitingdialog and some warnings when the user tries to exit the page. Loading a page in an IFrame can take some time and this code is doing it twice.