最近我用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);
有没有什么问题啊?
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);
有没有什么问题啊?
s.PutNextEntry(entry);改成
FileInfo info = new FileInfo(file);
ZipEntry entry = new ZipEntry(info.Name);
s.PutNextEntry(entry);
应当就可以了