Sharepoint Teamsite-calendar-webpart - 将约会保存到 outlook

Sharepoint Teamsite-calendar-webpart - save appointment to outlook

有没有办法通过 javascript 将日历条目保存到 sharepoint-calendar webpart 中的个人 outlook-calendar?

我想将在共享点日历​​中创建的条目直接保存到创建它的用户的个人 Outlook 日历中。

任何提示如何做到这一点?

所以,答案是"kind of"。

从技术上讲,您不必编写 JavaScript 来实现此目的,因为 SharePoint 具有内置服务 URL,可以将 .ICS 文件下载到用户的计算机,以及用户的任何文件默认日历系统(例如 Outlook)会将其作为新日历项目打开。

虽然如果您想为某个特定事件提供日历项下载,您可以手动构造此 link,但您当然可以使用 JavaScript 动态填充此 [= 中的参数值48=],这可能比必须单独查找这些值以手动构造 link.

更容易

你可以提供一个hyperlink生成.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 – URL 指向托管日历的站点 LIST_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 为每个事件生成此 link 的人员的示例,可以将以下代码放在与日历视图 Web 部件位于同一页面上的脚本编辑器 WebPart 中, 它会在每个事件前插入一个向下箭头字符 link ,这将触发该事件的 .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")