TechArena Community

TechArena Community (http://forums.techarena.in/)
-   Software Development (http://forums.techarena.in/software-development/)
-   -   Create zip file using C# (http://forums.techarena.in/software-development/1194849.htm)

Chrisch 10-06-2009 09:52 AM

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.

Katty 10-06-2009 10:02 AM

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


Walby 10-06-2009 10:06 AM

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


Aberto 10-06-2009 10:10 AM

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



All times are GMT +5.5. The time now is 10:08 PM.