Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / March 2006

Tip: Looking for answers? Try searching our database.

Send files to Compressed (zipped) folder

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Amelyan - 07 Mar 2006 16:28 GMT
I have a bunch of files I need to put into Compressed (zipped) Folder,
MyFiles.zip file, similarly to what Windows XP does when you send files to
compressed zipped folder.  What is the simplest way to compress these files
into a .zip?

I found System.IO.Compression, but I am not sure how to use it to do what I
need to do.  Does anyone have an example of how to send a bunch of files
into compressed (zipped) folder?

Thanks,
William Stacey [MVP] - 08 Mar 2006 05:08 GMT
You could do something like:

private void button21_Click_1(object sender, EventArgs e)

{

   // Note: Add a ref to the Com dll 'Microsoft Shell Controls And
Automation' in your project.

   // Creates a new zip container and adds directory to it.

   string zipFile = @"c:\myzip.zip";

   if (!System.IO.File.Exists(zipFile))

       System.IO.File.Delete(zipFile);

   using(FileStream fs = new FileStream(zipFile, FileMode.Create,
FileAccess.Write))

   {

       byte[] emptyzip = new byte[] { 80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

       fs.Write(emptyzip, 0, emptyzip.Length);

   }

   //Copy a folder and all its contents into zip file.

   Shell32.ShellClass sc = new Shell32.ShellClass();

   Shell32.Folder SrcFlder = sc.NameSpace(@"C:\temp\sampleapp");

   Shell32.Folder DestFlder = sc.NameSpace(zipFile);

   Shell32.FolderItems items = SrcFlder.Items();

   DestFlder.CopyHere(items, 20);

   Console.WriteLine("Done.");

}

Signature

William Stacey [MVP]

|I have a bunch of files I need to put into Compressed (zipped) Folder,
| MyFiles.zip file, similarly to what Windows XP does when you send files to
[quoted text clipped - 6 lines]
|
| Thanks,
Amelyan - 08 Mar 2006 22:31 GMT
Hi William,

I created a new project and added your code to main function.  I also added
shell32.dll from c:\windows\System32 folder.  I provided c:\temp as my
source folder that contains a bunch of files and folders.

However, when I run the program, it creates a myzip.zip that is 24bytes in
size, and when I open it, it is blank.  Is there anything that I missed?

Thanks,

> You could do something like:
>
[quoted text clipped - 56 lines]
> |
> | Thanks,

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.