Subscribe to Subscribers
Talk to Webmaster Tony John

Online Members

Raghav
More...

Resources » Code Snippets » ASP.NET WebForms

How to UnZip files in ASP.NET?


Posted Date:     Category: ASP.NET WebForms    
Author: Member Level: Diamond    Points: 45


In this article I am going to explain about how to Unzip zip files through ASP.NET. I have used Ionic.Zip dll to extract that zip files into normal files.



 


Description :


In my previous articles I was explained in detailed about how to create zip files in windows and web applications.

Zip file in ASP.NET

Zip file in C#.NET

Here I am going to explain how to extract that zip files in to normal files using ASP.NET . Two ways I am extract zip file

1) Fully extract all files in to destination folder

2) Extract only jpg files in to destination folder

Server side


I have statically mentioned source zip folder path and destination folder path etc.


using Ionic.Zip;
using System.IO;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
//UnZip Process
protected void BtnUnzip_Click(object sender, EventArgs e)
{
//source location of zip file
string sourceLocation = "D:\\images.zip";
//After extract where placed that files
string destLocation = "D:\\destfolder";
//Conditional extract and placed in this folder
string CondFiles = "D:\\condfolder";

//Extract all files in the zip file
using (ZipFile zip1 = ZipFile.Read(sourceLocation))
{
//Full file extract code
foreach (ZipEntry e1 in zip1)
{
e1.Extract(destLocation, ExtractExistingFileAction.OverwriteSilently);
}
//Based on the conditions to extract
foreach (ZipEntry e2 in zip1)
{
//Extract only txt files in extract folder
if (e2.FileName.ToString().Substring((e2.FileName.LastIndexOf('.') + 1), (e2.FileName.ToString().Length - e2.FileName.LastIndexOf('.') - 1)) == "jpg")
{
e2.Extract(CondFiles, ExtractExistingFileAction.OverwriteSilently);
}
}
}
}
}

Source code:


Client Side: ASP.NET
Code Behind: C#

Conclusion

I hope this code snippet is help you to know about unzip zip files through ASP.NET.

Attachments
  • UnZip_Source (43965-73836-UnZip-Source.rar)





  • Did you like this resource? Share it with your friends and show your love!


    Responses to "How to UnZip files in ASP.NET?"
    Author: Fajar    21 Jul 2012Member Level: Bronze   Points : 0
    thank info


    Feedbacks      

    Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: How to resize uploaded image in ASP.NET?
    Previous Resource: How to get last inserted ID from ASP.NET Code behind?
    Return to Resources
    Post New Resource
    Category: ASP.NET WebForms


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    Unzip in ASP.NET  .  
    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.