how to open Document's library upload file dialog? RRS feed

  • Question

  • Hello,

    I have a task list. User can attach file to the the task. What I want to do is to upload that file to the document library instead of saving it as an attachment. I want to display document's library upload or edit dialog to save the attachment. The dialog should appear when save button of task list item is clicked.  After saving file in a document library, both dialogs (task list and document upload) should close.

    How can I achieve this?


    Tuesday, April 29, 2014 1:40 PM


  • Hi,

    By investigating the “Add document” button of the Document Library, we can see the “onclick” property of it like this:

    Then we can create an extra button in the NewForm page of the Task list for the uploading job using JavaScript.

    Please add the script below into a Content Editor Web Part in the NewForm page:

    <script type="text/javascript" src=""></script>
    <script type="text/javascript">
      var $t = $("#bt1"); 
      $t.attr('onclick','javascript:NewItem2(event, "http://yoursite/_layouts/Upload.aspx?List={B71E38C1-AF65-4DC6-9CBF-9AE6802B94CD}&RootFolder=");javascript:return false;');
    <input id="bt1" type="button" value="Upload to Document Library"/>

    Then we will have such a NewForm page in the Task list:


    When we add an item in the task list, in the NewForm page, we can upload a document to a specific Document Library by click the newly added button. Once the document is uploaded, then we will return to the NewForm page to fill in other columns needed.

    Here is a link about how to add code into page via Content Editor Web Part:

    Best regards

    Patrick Liang
    TechNet Community Support

    Wednesday, April 30, 2014 6:54 AM