0

I have the code from Here to my document library

The script basically opens the edit form when you Drag & Drop files into Document library.

The code seems to work fine, however I am getting this pop up from Internet Explorer

To display the webpage again, Internet Explorer needs to resend the information you've previously submitted. If you were making a purchase, you should click the Cancel to avoid a duplicate transaction. ... Otherwise, click Retry to display the webpage again

Maybe it can be something related to the script?

1

Modify the code as below.

<script type="text/javascript">
(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.href = location.href;
                    }
                }
                openEditForItem();
            }, function (error, args) {
                    console.log("failed to get new uploaded items");
                    console.log(error);
                    console.log(args);
                });
        }
    }
})(window);
</script>

And add the SharePoint site to to the Trusted Sites Zone and adjust the following Internet Explorer Security Setting:

1.Click Tools, then Internet Options

2.Select the Security Tab, then Trusted Sites

3.Click Custom Level

4.Select Enable under Automatic Prompting for Download

5.Click OK to save the setting

  • thank you. Adding the code seemed to fix the problem. Is there a way to modify the code so that when I upload multiple files via Drag&Drop options, the metadata dialog to show up only once and then all the files to get the same metadata? It would be good to not fill the metadata for 10 files but instead only do it once – Ed1995 May 22 at 14:16
  • can you please help me with the question above . would really appreciate it @LZ_MSFT – Ed1995 May 26 at 19:05
  • The code only work for upload one file, if you upload multiple files, I suggest you use the OOTB "Upload" button. – LZ_MSFT May 27 at 2:18
  • Can you tell me how to use OOTB "Upload" button becauseas far as I know if I use the upload button on sharepoint I can onlz select one file . – Ed1995 May 27 at 6:29
  • Click "Upload" button->"Files", to select multiple files, we can use Ctrl+ click file. – LZ_MSFT May 27 at 7:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.