Greetings,
We are unzipping the files which are originally zipped through windows xp zipping utility. While unziping the file through code, the modified time of the files in that zip archive gets changed when extracted. We want to retain it to original in un-zipping. Please help. We are using following code snippet for unzipping.
=========================================================
public static string unzipThroughCSharp(string filename, string targetdir, bool overwrite, string password)
{
try
{
ICSharpCode.SharpZipLib.Zip.ZipInputStream inputStrm = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(File.OpenRead(filename));
inputStrm.Password = password;
ICSharpCode.SharpZipLib.Zip.ZipEntry nextEntry = inputStrm.GetNextEntry();
while (nextEntry != null)
{
if (nextEntry.Name.LastIndexOf("/") != nextEntry.Name.Length - 1)
{
if (nextEntry.Name.IndexOf("/") > 0)
{
if (!(Directory.Exists(targetdir + @"\" + nextEntry.Name.Replace("/", @"\").Substring(0, nextEntry.Name.Replace("/", @"\").LastIndexOf(@"\")))))
{
Directory.CreateDirectory(targetdir + @"\" + nextEntry.Name.Replace("/", @"\").Substring(0, nextEntry.Name.Replace("/", @"\").LastIndexOf(@"\")));
}
}
FileStream tmpStrm;
byte[ tmpBuffer = new byte[2049];
int tmpLength = -1;
if (overwrite == true)
{
tmpStrm = new FileStream(Path.Combine(targetdir, nextEntry.Name), FileMode.Create);
}
else
{
tmpStrm = new FileStream(Path.Combine(targetdir, nextEntry.Name), FileMode.CreateNew);
}
while (true)
{
tmpLength = inputStrm.Read(tmpBuffer, 0, tmpBuffer.Length);
if (tmpLength > 0)
{ tmpStrm.Write(tmpBuffer, 0, tmpLength); }
else
{ break; }
}
tmpStrm.Flush();
tmpStrm.Close();
nextEntry = inputStrm.GetNextEntry();
}
else
{
Directory.CreateDirectory(targetdir + @"\" + nextEntry.Name.Replace("/", @"\"));
nextEntry = inputStrm.GetNextEntry();
}
}
return "OK";
}
catch (Exception ex)
{
return ex.Message;
throw ex;
}
}