通过 CSOM 设置请求访问电子邮件地址
-
10-12-2019 - |
题
在服务器端对象模型中,可以通过属性设置请求访问电子邮件地址 SPWeb.RequestAccessEmail
(微软软件定义网络).
由于我们要将 SharePoint 租户迁移到 Office365,我正在寻找一种方法来设置此值。我知道可以在 UI 中手动执行此操作(站点设置 > 站点权限 > 访问请求设置),但由于我们有一些自助站点创建,因此不可能在每次创建网站时手动更改它。
可惜没有房产 Web.RequestAccessEmail
在客户端对象模型中。
有没有办法通过属性包(又名 Web.AllProperties["__SecretKey"]
)、网络服务(_vti_bin
, 等)或任何其他解决方法?
非常感谢任何帮助!
解决方案
在最新版本的“SharePoint Online Management Shell”(v16.0.4630.1200) 中,包含 Microsoft.SharePoint.Client.dll
添加属性 RequestAccessEmail
到 Web
班级。
下载: https://www.microsoft.com/en-us/download/details.aspx?id=35588
在 NuGet-Package 发布之前,您可以使用此 DLL。
编辑:自版本以来 16.1.4727.1200
的 Microsoft.SharePointOnline.CSOM
NuGet 打包 RequestAccessEmail
属性得到支持。
其他提示
不幸的是,该属性无法通过以下方式访问 CSOM
.
如何检索 Web 客户端对象的所有可用属性:
var allProperties = clientContext.Web.AllProperties;
clientContext.Load(allProperties);
clientContext.ExecuteQuery();
这是可能的,但在我看来是一种黑客行为。我写了一篇文章来讨论这是否是一种有效的方法 - 通过 IFrame 操作 SharePoint UI 以添加缺少的客户端功能
这是代码:
//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);
}
当用户尝试退出页面时,它应该包含在等待对话框和一些警告中。在 IFrame 中加载页面可能需要一些时间,并且此代码会执行两次。