Try this code what i have used in my application and it is working fine :-
public string Zip(string ZipFileName)
{
try
{
if (!File.Exists(ZipFileName))
{
return "";
}
using (ZipInputStream s = new ZipInputStream(File.OpenRead(ZipFileName)))
{
string fileName = "";
ZipEntry theEntry;
while ((theEntry = s.GetNextEntry()) != null)
{
string directoryName = Path.GetDirectoryName(theEntry.Name);
fileName = Path.GetFileName(theEntry.Name);
if (directoryName.Length > 0)
{
Directory.CreateDirectory(Server.MapPath("") + "\\XML\\" + directoryName);
}
if (fileName != String.Empty)
{
using (FileStream streamWriter = File.Create(Server.MapPath("") + "\\XML\\" + theEntry.Name))
{
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;
}
}
}
}
}
return fileName;
}
}
catch (Exception ex)
{
return "";
}
finally
{
}
}
calling to this function
------------------------------
string extractFileName = Server.MapPath("") + "\\XML\\" + Zip(FilePath);