我用SharpZipLib后,解压的路径总是一大串,\aa\bb\cc\myfile
能不能在压缩的时候就压缩成一个文件,一解压就直接是myfile?谢谢

解决方案 »

  1.   

    我贴我的代码
    public static void ZipFileMain(string[] FileToZip, string ZipedFile)
    {
    Crc32 crc = new Crc32();
    ZipOutputStream s = new ZipOutputStream(File.Create(ZipedFile));
      
    s.SetLevel(6); // 0 - store only to 9 - means best compression
      
    foreach (string file in FileToZip) 
    {
    //打开压缩文件
    FileStream fs = File.OpenRead(file);   
    byte[] buffer = new byte[fs.Length];
    fs.Read(buffer, 0, buffer.Length);
    ZipEntry entry = new ZipEntry(file);
       
    entry.DateTime = DateTime.Now;
       
    // set Size and the crc, because the information
    // about the size and crc should be stored in the header
    // if it is not set it is automatically written in the footer.
    // (in this case size == crc == -1 in the header)
    // Some ZIP programs have problems with zip files that don't store
    // the size and crc in the header.
    entry.Size = fs.Length;
    fs.Close();
       
    crc.Reset();
    crc.Update(buffer);
       
    entry.Crc  = crc.Value;
       
    s.PutNextEntry(entry);
       
    s.Write(buffer, 0, buffer.Length);
       
    }  
    s.Finish();
    s.Close();
    }
      

  2.   

    修改一下如下:
    ZipEntry entry = new ZipEntry(Path.GetFileName(file));