http://nuowei08.cnblogs.com/articles/455658.html
原文的标题:SQL Server report compress solution (Zip format)
原文的地址:http://www.codeproject.com/aspnet/prabhucode.asp
一下摘取部门生产zip的代码

将二进制的代码写到temp临时文件里面:
/*Parameters:

strpath – A string which holds the path where the 
          report files has to be saved.
strFileNameWithExt – A string which holds the name of 
   report file with extension (.html, .pdf, .xls etc).
byteResultStream – A byte array which holds the data 
   of the report in the form of bytes.

Method:
*/


private int WriteFile (string strPath, 
        
string strFileNameWithExt,byte[] byteResultStream)
{
     
int intResult = 0;
     FileStream stream 
= 
              File.OpenWrite(@strPath
+strFileNameWithExt);
     stream.Write(byteResultStream, 
0
                                byteResultStream.Length);
     stream.Close();
     intResult 
= ”1”;
     
return intResult;
     
#endregion

}

生成ZIP文件的过程:
*Parameters:

strFileName – A 
string which holds the filename without the extension

strFileNameWithExt – A 
string which holds the filename with extension

Method :
*/

private string CreateZip(string strFileName,string strFileNameWithExt)
{
      
string strZipFileName = string.Empty;
      Crc32 objCrc32 
= null;
      ZipOutputStream objZipOutputStream 
= null;
      ZipEntry objZipEntry 
= null;
      
string strPath = string.Empty;
      
#endregion
      strPath 
= HttpContext.Current.Server.MapPath(“\Temp”);
      
if (File.Exists(strPath+strFileNameWithExt))
      
{
           strZipFileName 
= strPath+strFileName+”.zip”;
           objCrc32 
= new Crc32();
           objZipOutputStream 
= 
               
new ZipOutputStream(File.Create(strZipFileName));
           objZipOutputStream.SetLevel(
6);
           FileStream objFileStream 
= 
                    File.OpenRead(strPath
+strFileNameWithExt);
           Byte[] abyBuffer 
= new Byte[objFileStream.Length];
           objFileStream.Read(abyBuffer, 
0, abyBuffer.Length);
           objZipEntry 
= new ZipEntry(strFileNameWithExt);
           objZipEntry.DateTime 
= DateTime.Now;
           objZipEntry.Size 
= objFileStream.Length;
           objFileStream.Close();
           objCrc32.Reset();
           objCrc32.Update(abyBuffer);
           objZipEntry.Crc 
= objCrc32.Value;
           objZipOutputStream.PutNextEntry(objZipEntry);
           objZipOutputStream.Write(abyBuffer, 
0, abyBuffer.Length);
           objZipOutputStream.Finish();
           objZipOutputStream.Close();
           strZipFileName 
= strFileName+”.zip”;
           
return strZipFileName;
      }

}
posted on 2006-07-20 22:13  nr  阅读(261)  评论(0)    收藏  举报