如何在Webpart中添加代码并在SharePoint的文档库中运行它 [英] How to add code in Webpart and run it in Document Library in SharePoint

查看:63
本文介绍了如何在Webpart中添加代码并在SharePoint的文档库中运行它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我知道 在哪里可以找到Webpart但不知道如何实现它或代码如何运行。

它应该位于我的一个文档库中,代码的任务是你用拖动上传的删除功能。

I know  where to find the Webpart but not sure how to implement it or how the code will run.
It should be located on one of my Document Libraries and the task of the code would be you upload with drag and drop feature.

代码会打开一个弹出操作对话框 询问元数据

the code would open a pop op dialog to  ask for the metadata

https://sharepoint.stackexchange.com/a/158373/84042

https://sharepoint.stackexchange.com/a/158373/84042

推荐答案

您好,

您的参考步骤(需要编辑权限)。

Steps for your reference(you need edit permission).




然后,将下面的脚本插入其中。

Then, insert below script into it.

<script>
(function (_window) {
    var maxTimeForReplaceUploadProgressFunc = 10000;
    function replaceUploadProgressFunc() {
        if (typeof _window.UploadProgressFunc != 'undefined') {
            _window.Base_UploadProgressFunc = _window.UploadProgressFunc;
            _window.UploadProgressFunc = Custom_UploadProgressFunc;
            console.log('replaced dialog');
        } else if (maxTimeForReplaceUploadProgressFunc > 0) {
            maxTimeForReplaceUploadProgressFunc -= 100;
            setTimeout(replaceUploadProgressFunc, 100);
        }
    }
    setTimeout(replaceUploadProgressFunc, 100);


    function Custom_UploadProgressFunc(percentDone, timeElapsed, state) {
        _window.Base_UploadProgressFunc(percentDone, timeElapsed, state);
        var messageType = ProgressMessage.EMPTY;
        switch (state.status) {
            case 1:
                messageType = ProgressMessage.VALIDATION;
                break;
            case 3:
                messageType = ProgressMessage.UPLOADING;
                break;
            case 4:
                messageType = ProgressMessage.UPLOADED;
                OpenEditFormForLastItem(state);
                break;
            case 5:
                messageType = ProgressMessage.CANCELLED;
                break;
        }

        function OpenEditFormForLastItem(state) {
            var caml = '';
            caml += "<View>";
            caml += "<Query>";
            caml += "<Where>";

            if (state.files.length > 1) {
                caml += "<In>";
                caml += "<FieldRef Name='FileLeafRef'/>";
                caml += "<Values>";
            } else {
                caml += "<Eq>";
                caml += "<FieldRef Name='FileLeafRef'/>";
            }

            state.files.forEach(function (file) {
                //only succesfull uploaded files that arent overwrites
                console.log(file);
                if (file.status === 5 /*&& !file.overwrite*/) {
                    caml += "<Value Type='File'>" + file.fileName + "</Value>";
                }
            }, this);

            if (state.files.length > 1) {
                caml += "</Values>";
                caml += "</In>";
            } else {
                caml += "</Eq>";
            }

            caml += "</Where>";
            caml += "<OrderBy><FieldRef Name='ID' Ascending='True' /></OrderBy>";
            caml += "</Query>";
            caml += "<ViewFields><FieldRef Name='ID' /></ViewFields>";
            caml += "<RowLimit>500</RowLimit>";
            caml += "</View>";
            console.log(caml);

            var cntxt = SP.ClientContext.get_current();
            var web = cntxt.get_web();
            var list = web.get_lists().getByTitle(window.ctx.ListTitle);
            var query = new SP.CamlQuery();
            query.set_viewXml(caml);
            var items = list.getItems(query);
            cntxt.load(list, 'DefaultEditFormUrl');
            cntxt.load(items);
            cntxt.executeQueryAsync(function () {
                var listEnumerator = items.getEnumerator();
                function openEditForItem() {
                    if (listEnumerator.moveNext()) {
                        var item = listEnumerator.get_current();
                        var id = item.get_id();

                        var options = SP.UI.


create_DialogOptions ();
options.title =" Add File Metadata" ;;
options.url = list.get_defaultEditFormUrl()+'?ID ='+ id;
options.autoSize = true;
options.dialogReturnValueCallback = openEditForItem;
SP.UI.ModalDialog.showModalDialog(options);
} else {
location.reload();
}
}
openEditFo rItem();
},function(error,args){
console.log("未能获取新上传的项目");
console.log(错误);
console.log(args);
});
}
}
})(窗口);
< / script>
create_DialogOptions(); options.title = "Add File Metadata"; options.url = list.get_defaultEditFormUrl() + '?ID=' + id; options.autoSize = true; options.dialogReturnValueCallback = openEditForItem; SP.UI.ModalDialog.showModalDialog(options); } else { location.reload(); } } openEditForItem(); }, function (error, args) { console.log("failed to get new uploaded items"); console.log(error); console.log(args); }); } } })(window); </script>

最好的问候,

Lee


这篇关于如何在Webpart中添加代码并在SharePoint的文档库中运行它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆