So, I'm fairly new to Sharepoint development. I have done a couple of webparts in the past and that about sums up my experience with sharepoint development.

I'm seeking your guidance on what's the best way (if its even possible) to:

Place a button on the sharepoint ribbon that only shows up on document libraries. When clicked the button downloads the selected documents to a network folder.

Let me know if this is possible and the best way to do it. Reading materials are appreciated.


Add your own CustomAction.

Use this code in CustomAction scheme:

Only for libraries:


Collect items id when click:

         Command='Yor own unique name' 
            var selectedItems = SP.ListOperation.Selection.getSelectedItems();
            var selectedIds = '';
            var listId = SP.ListOperation.Selection.getSelectedList();
            var i = 0;
                selectedIds += selectedItems[i].id + ',';
            selectedIds = escape(selectedIds.substring(0,selectedIds.length-1));
            var siteCollUrl = '{SiteUrl}';
            document.location.href= siteCollUrl + '/_layouts/*yourproject*/LoadFiles.aspx?ids='+selectedIds+'&amp;listId='+listId;""
    EnabledScript='javascript:SP.ListOperation.Selection.getSelectedItems().length > 1;'/>

In LoadFiles.aspx.cs:

protected void Page_Load(object sender, EventArgs e)
    string ids = Request.QueryString["ids"];
    using (SPSite site = new SPSite(SPContext.Current.Site.ID))
        using (SPWeb web = site.OpenWeb())
            SPList list = web.Lists[new Guid(Request.QueryString["ListId"])];
            foreach (string sid in ids.Split(','))
                SPListItem item = list.GetItemById(Convert.ToInt32(sid));
                SPFile itemfile = item.File;
                byte[] binFile = itemfile.OpenBinary();
                /*File ntwfile = File.Create(@"\\path\name.ext");...*/

I tried to modify my action for list's attachments.

  • app pool account for your webapp must has write permissions to your network folder. And, of course, it's only for on-premise SP.
    – AlexZh
    May 24 '18 at 11:14

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.