设为首页 收藏本站
查看: 599|回复: 0

[经验分享] Sharepoint学习笔记—ECMAScript对象模型系列-- 12、通过邮件发送带有Unique DocumentID的文档链接

[复制链接]

尚未签到

发表于 2015-9-24 10:54:18 | 显示全部楼层 |阅读模式
  在Sharepoint Document List默认的Ribbon中有这么一个发送Email的按钮,通过它可以把选中的文档分享给其它用户,如下图:
DSC0000.jpg
  但在发送的邮件内,默认Email按钮采用的是发送文档的Url地址,而并没有用到Sharepoint提供的Unique Document ID,使用文档的URL分享文档最明显的坏处就是,一旦我们移动了这个文档,那么这个URL就失效了,曾经分享过这个文档的用户要想再通过这个URL链接来获取这个文档就不再会成功。所以在这里,我们就通过ECMAscript结合Ribbon的相关知识来实现通过Sharepoint2010提供的Unique Document ID把文档通过邮件分享给其它用户的目标。下面进入操作步骤。
  1、新建一个空的Sharepoint项目
DSC0001.jpg
2、添加新的Feature,并命名为EmailLinkFeature,如下图
DSC0002.jpg
  3、添加新的空Element,命名为EmailLinkElement
DSC0003.jpg
  此Element的代码如下


<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <CustomAction
     Id="Ribbon.EmailUniqueLink"
     Location="CommandUI.Ribbon"
     RegistrationId="101"
     RegistrationType="List">
        <CommandUIExtension>
            <CommandUIDefinitions>
                <CommandUIDefinition
                   Location="Ribbon.Documents.Share.Controls._children">
                    <Button
                       Id="Ribbon.Documents.Share.EmailUniqueLink"
                       Command="Ribbon.Documents.Share.EmailUniqueLink"
                       Sequence="15"
                       Image16by16="/_layouts/$Resources:core,Language;/images/formatmap16x16.png"
                       Image16by16Top="-16"
                       Image16by16Left="-88"
                       Image32by32="/_layouts/$Resources:core,Language;/images/formatmap32x32.png"
                       Image32by32Top="-128"
                       Image32by32Left="-448"
                       Description="Sends the unique link to the document by e-mail"
                       LabelText="E-mail Unique Link"
                       ToolTipTitle="E-mail Unique Link"
                       ToolTipDescription="Sends the unique link to the document by e-mail"
                       TemplateAlias="o1"/>
                </CommandUIDefinition>
            </CommandUIDefinitions>
            <CommandUIHandlers>
                <CommandUIHandler
                   Command="Ribbon.Documents.Share.EmailUniqueLink"
                   CommandAction="javascript:EmailUniqueLink();"
                   EnabledScript="javascript:EnableEmailUniqueLink();"/>
            </CommandUIHandlers>
        </CommandUIExtension>
    </CustomAction>
    <CustomAction
       Id="Ribbon.Documents.Share.EmailUniqueLink.Script"
       Location="ScriptLink"
       ScriptSrc ="/_layouts/EmailLinkButton/EmailLinkButton.js"/>
</Elements>  
  4、添加Sharepoint的Layouts目录,并在此目录下新添加一个Javascript文件:EmailLinkButton.js文件
DSC0004.jpg
  EmailLinkButton.js的内容如下:


// This method will contain most of the code needed to request the unique url to the document
function EmailUniqueLink() {
    // First get the context and web
    var ctx = SP.ClientContext.get_current();
    this.web = ctx.get_web();
    // Get the current selected list, then load the list using the getById method of Web (SPWeb)
    var listId = SP.ListOperation.Selection.getSelectedList();
    var sdlist = this.web.get_lists().getById(listId);
    // Get the currently selected item of the list. This will return a dicustonary with an id field
    var items = SP.ListOperation.Selection.getSelectedItems(ctx);
    var mijnid = items[0];
    // Request the list item from the server using the getItemById method. This will load all properties.   
    // If needed, one could pre-request the fields to be loaded to preserve bandwidth.
    this.listItem = sdlist.getItemById(mijnid.id);
    // load the item in the context for batch operation.
    ctx.load(this.listItem);
    //Execute the actual script on the server side. Specify delegates to handle the response.
    ctx.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
// Delegate that is called when server operation is complete upon success.
function onQuerySucceeded(sender, args) {
    // Request url by using the get_item method. It will return the Url field type, which has a Url property.
    var url = this.listItem.get_item('_dlc_DocIdUrl').get_url();
    // Request the name of the document.
    var title = this.listItem.get_item('FileLeafRef');
    // Open a new e-mail in the default mail program.
    window.open('mailto:?subject=Emailing%3A%20' + title + '&body=' + url);
}
// Delegate that is called when server operation is completed with errors.
function onQueryFailed(sender, args) {
    alert('failed ' + args.toString());
}
// Method to enable/disable the e-mail unique button on the ribbon.
function EnableEmailUniqueLink() {
    // request number of selected items.
    var items = SP.ListOperation.Selection.getSelectedItems();
    var count = CountDictionary(items);
    // only return true is a single item is selected.
    return (count == 1);
}
  5、Build并部署我们的项目。
6、测试项目如下
DSC0005.jpg

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-118121-1-1.html 上篇帖子: MOSS/Sharepoint 控制视图页面访问权限开发的问题(代码法) 下篇帖子: SharePoint 2013 Troubleshooting——启用 Developer Dashboard
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表