最近我用SharpZipLib对项目生成的excel文件进行压缩,但是不不知道为什么当我打开这个压缩文件时它的目录居然把存在项目里的excel文件的目录全给显示出来了,即:
C:\Documents and Settings\w\桌面\EmployeeEvaluation\inetpub\wwwroot\WSPE\temp
我是把压缩的文件下载后放在桌面的。我想要的结果是:C:\Documents and Settings\w\桌面\temp\+被压缩的文件。
请问哪位大侠会啊!必重谢!
下面是压缩的方法:
public void ZipFileMain(string[] args)
{
string[] fileNames=Directory.GetFiles (args[0]);
Crc32 crc=new Crc32();
ZipOutputStream s=new ZipOutputStream(File.Create (args[1]));
s.SetLevel(6);
foreach(string file in fileNames)
{
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 ;
entry.Size =fs.Length ;
fs.Close ();
crc.Reset ();
crc.Update (buffer);
// entry.Crc =crc ;
s.PutNextEntry (entry);
s.Write (buffer,0,buffer.Length );


}
s.Finish ();
s.Close ();
}
调用时:                             
                                    string[] FileProperties=new string [2];
                                    FileProperties[0]=Server.MapPath("temp/");
FileProperties[1]="C:/temp/EmployeeEvaluation.zip";
ZipClass zc=new ZipClass ();
zc.ZipFileMain (FileProperties);
有没有什么问题啊?

解决方案 »

  1.   

    没有用过SharpZipLib,不过应该有属性可以设置压缩文件时是包括绝对路径名或者相对路径名的,WinRAR是可以的,猜想SharpZipLib应该会支持。
      

  2.   

    设置一下Entry的Name应该就可以了。
      

  3.   

    Entry中的Name属性是设置什么的啊?为什么在设置的时侯说它是只读的,不能设置呢。所以这还是不能解决问题的所在啊。
      

  4.   

    我想只要在创建 FileEntry时设置文件的相对路径名就可以了吧ZipEntry entry = new ZipEntry(file);
    s.PutNextEntry(entry);改成
    FileInfo info = new FileInfo(file);
    ZipEntry entry = new ZipEntry(info.Name);
    s.PutNextEntry(entry);
    应当就可以了