January 6, 2012

Create Zipped file using System.IO.Packaging

I was using DotNeZip to create zipped files , It was working perfect which can be checked at below post
http://www.dotnetissues.com/2011/12/code-to-create-zip-file-and-download.html

But when I tried to make in run on Godaddy Shared hosting I got security exceptions .
Then I used System.IO.Packaging which is available in .netframework 3.5/4.0 .
To use this first you 'll have to add reference of windowbase.dll in

Use below namespace  

using System.IO.Packaging;


2. Use below sample code to create zipped file.

public void ZipFiles2(DataSet ds,String ZipFileName)
{
   for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
   {
      String filePath = ds.Tables[0].Rows[i]["FileURL"].ToString().Remove(0, 1).ToString();
      AddFileToZip(ZipFileName,Server.MapPath("~/") + filePath);
   }
}

No comments:

Post a Comment