//-----------------------------------------------------------------------
// <copyright file="DownloadAsZipAction.cs" company="motion10">
// Copyright (c) motion10. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
using System.Globalization;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
namespace Motion10.SharePoint2007 { public class DownloadAsZipAction : MenuItemTemplate { /// <summary>
/// Initializes a new instance of the <see cref="DownloadViewAsZipAction"/> class.
/// </summary>
public DownloadAsZipAction()
: base("Download as Zip", "/_layouts/images/ICZIP.GIF") { base.Description = "Download selected files or complete view if no items selected.";
}
/// <summary>
/// Sends the content of the control to the specified <see cref="T:System.Web.UI.HtmlTextWriter"></see> object, which writes the content that is rendered on the client.
/// </summary>
/// <param name="output">The HtmlTextWriter object that receives the server control content.</param>
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
[SharePointPermission(SecurityAction.LinkDemand, ObjectModel=true)]
protected override void Render(System.Web.UI.HtmlTextWriter output) { ListViewWebPart listViewWebPart = FindListView(this.Parent);
if (listViewWebPart == null) { this.Visible = false;
}
if (this.Visible) { string navigateUrl = string.Format(CultureInfo.InvariantCulture,
"{0}/_layouts/DownloadAsZip.ashx?List={1}&View={2}&Item=", SPContext.Current.Web.Url,
listViewWebPart.ListName,
listViewWebPart.ViewGuid);
string clientClick = string.Format(CultureInfo.InvariantCulture,
"window.location = '{0}' + GetSelectedItemsString('WebPart{1}')", navigateUrl,
listViewWebPart.Qualifier);
this.ClientOnClickScript = clientClick;
}
base.Render(output);
}
protected ListViewWebPart FindListView(Control parent) { ListViewWebPart retVal = parent as ListViewWebPart;
if (retVal != null) { return retVal;
}
if (parent.Parent == null) return null;
return FindListView(parent.Parent);
}
}
}