您的位置:首页 > 其它

Custom Ribbon Action (DownLoad Multiple File) -------------SharePoint 2010

2010-10-13 13:43 351 查看
Below is a screenshot of my project:

代码

function enable()
{
var items = SP.ListOperation.Selection.getSelectedItems();
var itemCount = CountDictionary(items);
return (itemCount > 0);
}
function downloadZip()
{
var context = SP.ClientContext.get_current();
this.site = context.get_site();
this.web = context.get_web();
context.load(this.site);
context.load(this.web);
context.executeQueryAsync(
Function.createDelegate(this, this.onQuerySucceeded),
Function.createDelegate(this, this.onQueryFailed) ); }
function onQuerySucceeded()
{
var items = SP.ListOperation.Selection.getSelectedItems();
var itemCount = CountDictionary(items);
if (itemCount == 0) return;
var ids = "";
for (var i = 0; i < itemCount; i++)
{
ids += items[i].id + ";";
}
//send a request to the zip aspx page.
var form = document.createElement("form");
form.setAttribute("method", "post");
form.setAttribute("action", this.site.get_url() + this.web.get_serverRelativeUrl() + "/_layouts/SPMultipleFileDownLoad/downloadzip.aspx");
var hfSourceUrl = document.createElement("input");
hfSourceUrl.setAttribute("type", "hidden");
hfSourceUrl.setAttribute("name", "sourceUrl");
hfSourceUrl.setAttribute("value", location.href);
form.appendChild(hfSourceUrl);
var hfItemIds = document.createElement("input")
hfItemIds.setAttribute("type", "hidden");
hfItemIds.setAttribute("name", "itemIDs");
hfItemIds.setAttribute("value", ids);
form.appendChild(hfItemIds);
document.body.appendChild(form);
form.submit();
}
function onQueryFailed(sender, args)
{
this.statusID = SP.UI.Status.addStatus("Download as Zip:", "Downloading Failed: " + args.get_message() + " <a href='#' onclick='javascript:closeStatus();return false;'>Close</a>.", true);
SP.UI.Status.setStatusPriColor(this.statusID, "red");
}

So how does this actually all look when the user is using it? Below is the hierarchy of an example document library I have:





Documents
Folder A (Folder)
Subfolder in Folder A (Folder)
Sub Sub Folder (Folder)
Versioning Flow (Visio diagram)

Business Brief_SoW (Word document)
SoW_Phase1 (Word document)

Request Email (Text file)
Users and Roles (Excel file)

Issues (Excel file)
Product_Planning (Excel file)

The user has selected some documents and a sub-folder so my custom ribbon button is enabled:





The user clicks on this button and this feature executes and after it’s complete the user is prompted with this (note, the filename is a timestamp):







Reference :http://www.deviantpoint.com/post/2010/05/08/SharePoint-2010-Download-as-Zip-File-Custom-Ribbon-Action.aspx
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: