Domanda

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.

È stato utile?

Soluzione

Add your own CustomAction.

Use this code in CustomAction scheme:

Only for libraries:

RegistrationId="101"

Collect items id when click:

<CommandUIHandlers>
   <CommandUIHandler 
         Command='Yor own unique name' 
         CommandAction=""javascript:
            var selectedItems = SP.ListOperation.Selection.getSelectedItems();
            var selectedIds = '';
            var listId = SP.ListOperation.Selection.getSelectedList();
            var i = 0;
            while(i!=selectedItems.length)
            {
                selectedIds += selectedItems[i].id + ',';
                i++;
            }
            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;'/>
 </CommandUIHandlers>

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top