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
代码
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
相关文章推荐
- Custom Ribbon Action (DownLoad Multiple File) -------------SharePoint 2010
- [转]SharePoint 2010 Download as Zip File Custom Ribbon Action
- SharePoint 2010 Download as Zip File Custom Ribbon Action
- 如何在SharePoint 2010 中添加选项卡到Ribbon功能区
- SharePoint 2010 UI 定制化系列之定制Ribbon: Server Ribbon 架构的探讨和理解
- 在SharePoint 2010系统中安装RBS FILESTREAM Provider
- SharePoint 2010 Ribbon的实现
- SharePoint 2010自定义开发Ribbon
- Sharepoint 2010设置Ribbon中的Tab为默认
- 如何在SharePoint 2010 中添加选项卡到Ribbon功能区
- Sharepoint学习笔记—Ribbon系列-- Reference : Sharepoint 2010 Ribbon Locations
- SharePoint 2010 MasterPage去Ribbon 的方法
- SharePoint 2010 Ribbon的实现
- SharePoint 2010 技巧系列: 控制Ribbon菜单权限(SiteActions的例子)
- SharePoint 2010 RBS FILESTREAM Provider 的“垃圾收集”
- SharePoint 2010 MasterPage 去Ribbon的方法
- 关闭SharePoint 2010 customErrors
- SharePoint 2010 移除Ribbon菜单中的命令项
- sharepoint 2010 custom webpart与custom webpart的联动方法
- 在SharePoint 2010系统中安装RBS FILESTREAM Provider