نمایش نتایج 1 تا 1 از 1

نام تاپیک: ی کد با DLL برای Zip

  1. #1

    ی کد با DLL برای Zip

    ی کد با DLL برای Zip کردن براتون میذارم
    	ZipOutputStream zos = null;
    protected void Button1_Click(object sender, EventArgs e)
    {
    string[] pathCollection = new string[2];
    PathCellction[0] = "c:\\folder1";
    PathCellction[1] = "c:\\folder2";
    StartZip(pathCollection, "filename");
    }

    protected void StartZip(string[] pathCollection, string strFileName)
    {
    MemoryStream ms;
    Response.ContentType = "application/octet-stream";
    strFileName = HttpUtility.UrlEncode(strFileName).Replace('+', ' ');
    Response.AddHeader("Content-Disposition", "attachment; filename=" + strFileName + ".zip");
    ms = new MemoryStream();
    zos = new ZipOutputStream(ms);
    addZipEntry(pathCollection);
    ms.Close();
    zos.Finish();
    zos.Close();
    Response.Clear();
    Response.BinaryWrite(ms.ToArray());
    Response.End();
    }

    protected void addZipEntry(string[] pathCollection)
    {
    for (int i = 0; i < pathCollection.Length; i++)
    {
    string strPath = pathCollection[i];
    addZipEntry(strPath, strPath.LastIndexOf("\\") + 1);
    }
    }

    protected void addZipEntry(string strPath, int baseIndex)
    {
    DirectoryInfo di = new DirectoryInfo(strPath);
    foreach (DirectoryInfo item in di.GetDirectories())
    {
    addZipEntry(item.FullName, baseIndex);
    }
    foreach (FileInfo item in di.GetFiles())
    {
    FileStream fs = File.OpenRead(item.FullName);
    byte[] buffer = new byte[fs.Length];
    fs.Read(buffer, 0, buffer.Length);
    string strEntryName = item.FullName.Remove(0, baseIndex);
    ZipEntry entry = new ZipEntry(strEntryName);
    zos.PutNextEntry(entry);
    zos.Write(buffer, 0, buffer.Length);
    fs.Close();
    }
    }
    فایل های ضمیمه فایل های ضمیمه
    • نوع فایل: zip Zip.zip‏ (77.3 کیلوبایت, 6 دیدار)

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •