|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Services
Chapters
Feature Zones
|
Note: This is an unedited contribution. If this article is inappropriate,
needs attention or copies someone else's work without reference then please
Report This Article
Download ZipHandlerSite.zip - 98.42 KB IntroductionThe The handler is very useful for several purposes:
My company website uses the handler for our Developer Labs area where samples are available through zip files for users to download or as single files for users who just browse concepts. BackgroundDevelopers need a basic understanding of ASP.NET to use this component effectively. Knowledge of the Using the codeThe handler is configured with a single line in the web.config file: <configuration>
<system.web>
<httpHandlers>
<add path="ZipEntry.axd" verb="GET" type="Elsinore.Website.ZipEntryHandler" />
</httpHandlers>
</system.web>
</configuration>
Once configured, zip entries are available as URLs. An example URL: http://www.mysite.com/ZipEntry.axd?ZipFile=test.zip&ZipEntry=test.cs
This can be broken down as follows: http://www.mysite.com/<HandlerPath>?ZipFile=<ZipFileVirutalPath>&ZipEntry=<ZipEntryPath>
These URLs can be hardcoded as above, or methods on the <%@ Page Language="C#" %>
<script runat="server">
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
this.zipFileRepeater.DataSource = Elsinore.Website.Utility.GetVirtualFilePaths("~/Content", this.Context);
this.zipFileRepeater.DataBind();
}
</script>
<html>
<head>
<title>Zip Entry Example Page</title>
</head>
<body>
<asp:Repeater runat="server" ID="zipFileRepeater">
<ItemTemplate>
<p>
<asp:HyperLink runat="server" NavigateUrl="<%# Container.DataItem %>">
Download <%# Container.DataItem %>
</asp:HyperLink>
</p>
<p>
Contents:</p>
<ul>
<asp:Repeater runat="server" DataSource="<%# Elsinore.Website.ZipEntryHandler.GetZipEntries((string)Container.DataItem, this.Context) %>">
<ItemTemplate>
<li>
<asp:HyperLink runat="server" NavigateUrl="<%# ((Elsinore.Website.ZipEntryInfo)Container.DataItem).Url %>">
View <%# ((Elsinore.Website.ZipEntryInfo)Container.DataItem).Name %>
</asp:HyperLink>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
<br />
</ItemTemplate>
</asp:Repeater>
</body>
</html>
In the code above the outer repeater is driven by enumerating the zip files in the Content directory. The inner repeater uses the
The "View" links provide quick-and-easy access to the contents of the zip file. Points of InterestI hoped to use classes in the new
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||