Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 10-06-2009
Member
 
Join Date: Apr 2009
Posts: 79
Create zip file using C#

Is there any program in C# to create zip file. I want to write an application in C# .NET 2.0 that allow user to use zip file. The zip file created must able to read any files from archives into memory and create new file. Any recommendations and suggestions are appreciated.
Reply With Quote
  #2  
Old 10-06-2009
Member
 
Join Date: May 2008
Posts: 2,008
Re: Create zip file using C#

Code:
private void zip(string[] args)

{

//Create an zip file to read any file

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 };

FileStream fls = File.Create(args[1]);

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

fls.Flush();

fls.Close();

fls = null;l

Shell32.ShellClass fs= new Shell32.ShellClass();
Shell32.Folder SrcFlder = fs.NameSpace(args[0]);
Shell32.Folder DestFlder = fs.NameSpace(args[1]);
Shell32.FolderItems items = SrcFlder.Items();
DestFlder.CopyHere(items, 0);
System.Threading.Thread.Sleep(500);
}

string[] ster = new string[2];
ster[0] = zipFolderPath; 
str[1] = _startUpPath + "\\" + "Attachment.zip"; 
zip(ster);
Reply With Quote
  #3  
Old 10-06-2009
Member
 
Join Date: Jan 2009
Posts: 199
Re: Create zip file using C#

Here is program to create zip file in C#.net :


Code:
        FileStream sourceFile = File.OpenRead(@"C:\zip.xml");
        FileStream destFile = File.Create(@"C:\zip.zip");

        GZipStream compStream = new GZipStream(destFile, CompressionMode.Compress);

        try
        {
            int value = sourceFile.ReadByte();
            while (value!= -1)
            {
                compStream.WriteByte((byte)value);
                value = sourceFile.ReadByte();
            }
        }
        finally
        {
            compStream.Dispose();
        }
Reply With Quote
  #4  
Old 10-06-2009
Member
 
Join Date: Dec 2008
Posts: 177
Re: Create zip file using C#

Code:
private void ZipFiles(String[] Files, String Output)
        {
            for (int g = 0; g < Files.Length; g++)
            {
                System.IO.FileStream stream = new System.IO.FileStream("" + g, System.IO.FileMode.Open);
                System.IO.Compression.GZipStream gzip = new System.IO.Compression.GZipStream(stream, System.IO.Compression.CompressionMode.Compress, false);
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Create zip file using C#"
Thread Thread Starter Forum Replies Last Post
Driver error: Cannot create a file when that file already exists Nickason Windows XP Support 1 21-03-2013 03:52 PM
cannot create PDF file Rafferty!!! Windows Software 7 12-11-2011 10:04 PM
Windows 7: Unable to create file with File system error (65535) TheHibiscus Operating Systems 4 23-01-2011 07:07 PM
Windows Backup : Cannot create a file when that file already exists Animorc Operating Systems 3 04-06-2009 09:40 AM
Cannot create a file when that file already exists Agilent Windows XP Support 6 09-09-2008 10:24 AM


All times are GMT +5.5. The time now is 03:18 PM.