Click here to Skip to main content
16,019,018 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
please help me i am trying to create zip dynamicaly when user clicks on button and adding files in to it.files are of image,pdf,text audio,video,zip type. i tried following code - it downloads the file in zip folder but contents of file not appearing:
C#
Crc32 crc = new Crc32();

ZipOutputStream s = new ZipOutputStream(File.Create(@"C:\Documents and Settings\admin\My Documents\Downloads\Evidence.zip"));

s.SetLevel(9); // 0 - store only to 9 - means best compression

FileStream fs = File.OpenRead(@"c:\boot.ini");

byte[] buffer = new byte[fs.Length];

fs.Read(buffer, 0, buffer.Length);



if (ds.Tables[0].Rows.Count > 0)
{
    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
    {
        string fileNamePath = Convert.ToString(ds.Tables[0].Rows[i]["EvidencePath"]);
        string fileNmae = Convert.ToString(ds.Tables[0].Rows[i]["EvidenceName"]);
        ZipEntry entry = new ZipEntry(ZipEntry.CleanName(@fileNmae));

        entry.DateTime = DateTime.Now;
        entry.Comment = "test file";

        entry.ZipFileIndex = i + 1;

        crc.Reset();

        crc.Update(buffer);

        entry.Crc = crc.Value;

        s.PutNextEntry(entry);

        s.Write(buffer, 0, buffer.Length);



    }
    s.Finish();

    s.Close();
    fs.Close();
}

ShowMessageBox("Downloaded....");
Posted
Updated 2-Jul-12 19:48pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900