![]() |
Enterprise Systems »
SharePoint Server »
Custom Controls
Intermediate
License: The GNU General Public License (GPL)
Download SharePoint Zipped List ItemsBy Mohamed ZakiThis custom UI Action for SharePoint extends the lists action menu to allow users to zip document library items and download all of them with or without version. |
C# 2.0, Windows, Office, .NET 2.0, ASP.NET, Visual Studio, SQL 2005, IIS 6, Dev
|
|
Advanced Search |
|
|
|
||||||||||||||||
This custom UI Actions for SharePoint extends the lists action menu to allow users to zip document library items and download all of them with or without version.
The new menu added to the SharePoint document library Actions menu:

After clicking over the menu item:

the compressed file is downloaded:

The compressed file downloaded with the file versions:

First, we need to create a new feature that defines a new SharePoint Custom UI Action as below:
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction
Id="DownloadZippedItems.MenuLink"
Location="Microsoft.SharePoint.StandardMenu"
GroupId="ActionsMenu"
ControlAssembly="MZaki.CustomActions.DownloadZippedItems,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=da6289be64eaeba3"
ControlClass="MZaki.CustomActions.DownloadZippedItems">
</CustomAction>
</Elements>
In this custom action, we use a Control Assembly instead of redirecting to another URL. This assembly is responsible for rendering the menu and its sub menus and handling the postback event:
protected override void CreateChildControls()
{
if (!this.ChildControlsCreated)
{
base.CreateChildControls();
// Create the sub menu item
SubMenuTemplate mnuZipListItems = new SubMenuTemplate();
mnuZipListItems.Text = "Zip List Items";
mnuZipListItems.ImageUrl = "/_layouts/images/TBSPRSHT.GIF";
mnuZipListItems.Description = "Zip and download List Items";
//mnuZipListItems.ID = "downloadZipped";
//Add zip and download all
PostBackMenuItemTemplate mnuListItem =
new PostBackMenuItemTemplate();
mnuListItem.ID = "menu1";
mnuListItem.Text = "All Items";
//mnuListItem.ID = "mymenulistitemid";
mnuListItem.Description = "Zip and Download All Items";
mnuListItem.OnPostBack +=
new EventHandler<eventargs>(mnuListItem_OnPostBack);
//Add zip and download all with versions
PostBackMenuItemTemplate mnuListItem2 = new PostBackMenuItemTemplate();
mnuListItem2.Text = "All Items with Versions";
mnuListItem2.Description = "Zip and Download All Items";
mnuListItem2.ID = "menu2";
mnuListItem2.OnPostBack +=
new EventHandler<eventargs>(mnuListItem2_OnPostBack);
//Separator
MenuSeparatorTemplate separator = new MenuSeparatorTemplate();
//Current View only
PostBackMenuItemTemplate mnuListItemCurrentView =
new PostBackMenuItemTemplate();
mnuListItemCurrentView.Text = "Items In Current View";
mnuListItemCurrentView.Description = "Zip and Download All Items";
mnuListItemCurrentView.ID = "menu3";
mnuListItemCurrentView.OnPostBack +=
new EventHandler<eventargs>(mnuListItemCurrentView_OnPostBack);
//Current View only with versions
PostBackMenuItemTemplate mnuListItemCurrentViewVersions =
new PostBackMenuItemTemplate();
mnuListItemCurrentViewVersions.Text =
"Items In Current View With Versions";
mnuListItemCurrentViewVersions.Description =
"Zip and Download All Items";
mnuListItemCurrentViewVersions.ID = "menu4";
mnuListItemCurrentViewVersions.OnPostBack +=
new EventHandler<eventargs>(mnuListItemCurrentViewVersions_OnPostBack);
mnuZipListItems.Controls.Add(mnuListItem);
mnuZipListItems.Controls.Add(mnuListItem2);
mnuZipListItems.Controls.Add(separator);
mnuZipListItems.Controls.Add(mnuListItemCurrentView);
mnuZipListItems.Controls.Add(mnuListItemCurrentViewVersions);
this.Controls.Add(mnuZipListItems);
}
}
Now, in the postback handler, we simply retrieve the list item files and compress them to a temp directory, and force the browser to download the file.
void PushFileToDownload(string FilePath,string FileName)
{
FileInfo fInfo = new FileInfo(FilePath);
HttpContext.Current.Response.ContentType = "application/x-download";
HttpContext.Current.Response.AppendHeader("Content-Disposition",
"attachment; filename=" + FileName);
HttpContext.Current.Response.AddHeader("Content-Length", fInfo.Length.ToString());
HttpContext.Current.Response.WriteFile(FilePath);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
}
Here is the project page on CodePlex: http://codeplex.com/mzakicustomactions.
| You must Sign In to use this message board. | |||||||||||||||
|
|||||||||||||||
|
|||||||||||||||
|
|||||||||||||||
|
|||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 25 Oct 2008 Editor: Smitha Vijayan |
Copyright 2008 by Mohamed Zaki Everything else Copyright © CodeProject, 1999-2009 Web17 | Advertise on the Code Project |