Sharepoint Teamsite日历Web部件-将约会保存到outlook



有没有办法通过javascript将日历条目保存到sharepoint日历Web部件中的个人outlook日历中?

我想将sharepoint日历目录中创建的条目保存到创建它的用户的个人展望日历中。

有什么诀窍吗?

所以,答案是"有点"。

从技术上讲,您不必编写JavaScript来实现这一点,因为SharePoint有一个内置的服务URL,可以将.ICS文件下载到用户的机器上,无论该用户的默认日历系统(如Outlook(如何,都会将其作为新的日历项打开。

尽管如果您想为某个特定事件提供日历项下载,您可以手动构建此链接,但您当然可以使用JavaScript动态填充此URL中的参数值,这可能比手动构建链接时单独查找这些值更容易。

可以提供超链接以生成.ics文件的URL是https://**SITE_URL**/_vti_bin/owssvr.dll?CS=109&Cmd=Display&List={**LIST_GUID**}&CacheControl=1&ID=**EVENT_ID**&Using=event.ics

SITE_URL–托管日历的网站的URLLIST_GUID–日历列表的(GUID(唯一标识符EVENT_ID–日历事件的(整数(ID

例如:

https://mysharepointserver/sites/myteamsite/_vti_bin/owssvr.dll?CS=109&Cmd=Display&List={B2E3EC57-9BA6-46A2-B072-578C9796A42E}&CacheControl=1&ID=26&Using=event.ics

作为可以使用JavaScript为每个事件生成此链接的示例,以下代码可以放在与日历视图Web部件位于同一页面的脚本编辑器Web部件中,它将在触发该事件的.ics文件的每个事件链接前插入一个向下箭头字符。此脚本假设您的页面上已经加载了jQuery库,并且您需要将下面的字符串"NameOfYourEventsList"替换为事件列表的实际标题。

function lookupListBeforeAppendingCalendarLink() {
var context = new SP.ClientContext.get_current();
var web = context.get_web();
list = web.get_lists().getByTitle("NameOfYourEventsList");
context.load(list, 'Id');
context.executeQueryAsync(Function.createDelegate(this,listIdSuccess), Function.createDelegate(this,error));
}
function listIdSuccess() {
var listId = list.get_id();
appendAddToCalendarLink(listId);
}
function error(sender, args) {
console.log('Request failed. ' + args.get_message() +
'n' + args.get_stackTrace());
}
function appendAddToCalendarLink(listId) {
jQuery('.ms-acal-rootdiv .ms-acal-item').each(function () {
var currentCalendarAnchor = jQuery('a', jQuery(this));
var itemId = currentCalendarAnchor.attr('href').split('?ID=')[1];
currentCalendarAnchor.before("<a href='" + _spPageContextInfo.webServerRelativeUrl + "/_vti_bin/owssvr.dll?CS=109&Cmd=Display&List=" + listId + "&CacheControl=1&ID=" + itemId + "&Using=event.ics'>&darr;</a>");
});
}
function customizeCalendar() {
//if you know the list id, you can hard code it here, 
// otherwise use function to look it up first by List title
// var listId = 'B2E3EC57-9BA6-46A2-B072-578C9796A42E'
// appendAddToCalendarLink(listId);
lookupListBeforeAppendingCalendarLink();
}
ExecuteOrDelayUntilScriptLoaded(customizeCalendar, "sp.js")

最新更新