Results 1 to 4 of 4

Thread: Create zip file using C#

  1. #1
    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.

  2. #2
    Join Date
    May 2008
    Posts
    2,012

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

  3. #3
    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();
            }

  4. #4
    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);

Similar Threads

  1. Replies: 1
    Last Post: 21-03-2013, 03:52 PM
  2. cannot create PDF file
    By Rafferty!!! in forum Windows Software
    Replies: 7
    Last Post: 12-11-2011, 10:04 PM
  3. Windows 7: Unable to create file with File system error (65535)
    By TheHibiscus in forum Operating Systems
    Replies: 4
    Last Post: 23-01-2011, 07:07 PM
  4. Replies: 3
    Last Post: 04-06-2009, 09:40 AM
  5. Cannot create a file when that file already exists
    By Agilent in forum Windows XP Support
    Replies: 6
    Last Post: 09-09-2008, 10:24 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,190,250.66189 seconds with 16 queries