<%@ Page language="c#" Codebehind="UploadAndExtractZipFile.aspx.cs" AutoEventWireup="True" Inherits="EAUploadExamples.UploadAndExtractFile" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Upload archive and extract its on the server</title>
<link rel="stylesheet" href="ExamplesStyle.css">
<script type="text/javascript">
function ValidateFileExtantion()
{
var messageBox = document.getElementById('ValidationMessage');
if (document.getElementById('UploadingFile').value == '')
{
messageBox.innerHTML = 'Please select a file!';
return false;
}
else if (document.getElementById('ckbUnZip').checked && !EndsWith(document.getElementById('UploadingFile').value, '.zip'))
{
messageBox.innerHTML = 'Only zip file can be unzipped. Please select a zip archive!';
return false;
}
return true;
}
function EndsWith(sourceString, matchString)
{
var endOfSourceString = sourceString.substring(sourceString.length - matchString.length);
if (endOfSourceString.toLowerCase() != matchString.toLowerCase())
{
return false;
}
return true;
}
</script>
</HEAD>
<BODY>
This example demonstrates how to upload a zip archive and extract it on a
server.<br />
.NET Zip component <b>SharpZibLib</b> is used for extracting file on a server.
More about SharpZipLib library you can find on the official site:
http://www.icsharpcode.net/OpenSource/SharpZipLib/
<br />
<br />
<form id="Form1" method="post" runat="server" enctype="multipart/form-data" onsubmit="return ValidateFileExtantion();">
<div id="ValidationMessage" style="COLOR: #ff0000"> </div>
<table style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none">
<tbody>
<tr>
<td>
<asp:CheckBox id="ckbUnZip" runat="server" Text="UnZip"></asp:CheckBox>
</td>
<td>
<input type="file" id="UploadingFile" name="UploadingFile" size="40">
</td>
</tr>
<tr>
<td align="right" colspan="2">
<br />
<asp:Button id="Button1" runat="server" Width="80px" Text="Upload" onclick="Button1_Click"></asp:Button>
</td>
</tr>
</tbody>
</table>
<br />
<asp:Label id="lblResponse" runat="server"></asp:Label>
</form>
<hr />
<a target="_blank" href="http://www.easyalgo.com/quickstart/util/srcview.aspx?path=/Examples/EAUpload/UploadAndExtractZipFile.src">View C Sharp source code</a>
<a target="_blank" href="http://www.easyalgo.com/quickstart/util/srcview.aspx?path=/Examples/EAUpload/VBNET/UploadAndExtractZipFile.src">View VB NET source code</a>
</BODY>
</HTML>