carichi il file zippato e lo unzippi con asp.net
Allora,
in .net ho trovato questo componente da mettere nella cgi-bin (o solo bin, vattelo a ricordare come si chiama) di aruba http://www.icsharpcode.net/OpenSource/SharpZipLib/
una volta fatto, un esempio di codice te lo riporto qui:
codice:
<%@ Page Language="C#" AutoEventWireup="true" Debug="true" ContentType="text/xml" %>
<%@ Register TagPrefix="ic" Namespace="ICSharpCode.SharpZipLib" Assembly="ICSharpCode.SharpZipLib, Version=0.85.1.271, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, Safe=true" %>
<%@ import Namespace="ICSharpCode.SharpZipLib.Zip" %>
<%@ import Namespace="ICSharpCode.SharpZipLib.Checksums" %>
<%@ import Namespace="System.IO" %>
<script runat="server">
void Page_Load(Object sender, EventArgs e) {
string archiveId=Request.QueryString["id"];
if(archiveId.Trim().Length==0){
error("ArchiveId vuoto");
}else{
string fileZip=Server.MapPath("/public/archivi_photo_temp/"+archiveId+"/temp.zip");
string outputFolder=Server.MapPath("/public/archivi/"+archiveId+"/photos");
bool ret;
ret=UnZipFiles(fileZip,outputFolder,true);
if(!ret){
error("Error on unzipping file");
}else{
print(200, "Operazione effettuata correttamente");
}
}
}
private void error(String error)
{
// errore
print(100, error);
}
private void print(int status, String msg)
{
String printed;
printed = @"<?xml version=""1.0"" encoding=""iso-8859-1""?>";
printed += @"<status><code>" + status + @"</code><desc>" + msg + @"</desc></status>";
Response.Write(printed);
}
//OutputFolder è la direcotry dove salvare i file nello zip
public bool UnZipFiles(string zipPathAndFile, string outputFolder, bool deleteZipFile)
{
ZipInputStream s = new ZipInputStream(File.OpenRead(zipPathAndFile));
bool ret=false;
ZipEntry theEntry;
string tmpEntry = String.Empty;
while ((theEntry = s.GetNextEntry()) != null)
{
string directoryName = outputFolder;
string fileName = Path.GetFileName(theEntry.Name);
// create directory
if (directoryName != "")
{
Directory.CreateDirectory(directoryName);
}
if (fileName != String.Empty)
{
if (theEntry.Name.IndexOf(".ini") < 0)
{
string fullPath = directoryName + "\\" + theEntry.Name;
fullPath = fullPath.Replace("\\ ", "\\");
string fullDirPath = Path.GetDirectoryName(fullPath);
if (!Directory.Exists(fullDirPath)) Directory.CreateDirectory(fullDirPath);
FileStream streamWriter = File.Create(fullPath);
int size = 2048;
byte[] data = new byte[2048];
while (true)
{
size = s.Read(data, 0, data.Length);
if (size > 0)
{
streamWriter.Write(data, 0, size);
}
else
{
break;
}
}
streamWriter.Close();
}
}
}
s.Close();
if (deleteZipFile)
File.Delete(zipPathAndFile);
return true;
}
</script>
ti dovrebbe funzionare diretto così, non mi pare di avere usato una versione ricompilata.