zoukankan      html  css  js  c++  java
  • SharePoint 2010 使用客户端对象模型ECMAScript复制文件

    /// <reference path="D:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\MicrosoftAjax.js" />
    /// <reference path="D:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\SP.js" />
    /// <reference path="D:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\SP.Core.js" />
    function copyFile(sourceUrl, destinationUrl) {
        var ctx, file, notifyId;

        ctx = SP.ClientContext.get_current();

        file = ctx.get_web().getFileByServerRelativeUrl(sourceUrl);
        ctx.load(file);

        // Set a notification to the user that we are going to copy the file.
        notifyId = SP.UI.Notify.addNotification('Copying file...', true);

        ctx.executeQueryAsync(
            function (sender, args) {
                // File loaded. Now we want to copy the file. We'll use a nested AJAX call
                file.copyTo(destinationUrl, true);

                ctx.executeQueryAsync(
                    function (sender, args) {
                        // File copied successfully!
                        SP.UI.Notify.removeNotification(notifyId);

                        // Let the user know that the operation was successful
                        SP.UI.Notify.addNotification('File copied successfully', false);
                    },
                    function (sender, args) {
                        // Unable to copy file.
                        SP.UI.Notify.removeNotification(notifyId);

                        showError(args.get_message());
                    });
            },
            function (sender, args) {
                // Unable to locate file.
                SP.UI.Notify.removeNotification(notifyId);

                showError(args.get_message());
            });
    }
    function showError(msg) {
        var statusId;

        statusId = SP.UI.Status.addStatus('File Copy Error:', msg);
        SP.UI.Status.setStatusPriColor(statusId, 'red');

        // Remove the error message after 5 seconds
        window.setInterval(function(){SP.UI.Status.removeStatus(statusId);}, 5000);
    }

    原文参考:http://www.sharepointdevelopment.me/2011/05/working-with-files-in-sharepoint-from-ecma-script/

  • 相关阅读:
    Ubuntu下快速建立跨多个平台的cocos2d-x项目
    转盘抽奖效果练习
    javascript网页弹出层练习
    PHP中Terminal提示不是内部或外部命令,也不是可运行的程序问题解决
    网页授权获取用户信息(自我总结)
    用easywechat开发微信支付功能以及红包接口调用注意事项
    微信公众平台开发步骤(包括自定义菜单、网页授权、分享功能)
    laravel-wechat 配置安装
    第1讲 html介绍 html运行原理
    总结学习方向
  • 原文地址:https://www.cnblogs.com/sygwin/p/2241361.html
Copyright © 2011-2022 走看看