Results 1 to 6 of 6

Thread: [2.0] Zip and UNzip

  1. #1

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    [2.0] Zip and UNzip

    Dear All,
    How to zip and Unzip folders using J# Runtime component.
    Please mark you thread resolved using the Thread Tools as shown

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] Zip and UNzip

    There is code to do exactly that in the VB.NET CodeBank. You may also prefer to use #ZipLib, which now supports .NET 2.0.

    http://www.vbforums.com/showthread.php?t=413705
    Last edited by jmcilhinney; Jan 31st, 2007 at 02:52 AM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: [2.0] Zip and UNzip

    Thanks for the reply.I think it will be better ,if one module is added.That is check for the
    ziped contents with the content of the zipfile contents
    Please mark you thread resolved using the Thread Tools as shown

  4. #4

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: [2.0] Zip and UNzip

    Is there anymethod avl to convert the coding into C#
    Please mark you thread resolved using the Thread Tools as shown

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] Zip and UNzip

    There are code converters available, including those links in my signature, but don't assume that you can't do it yourself. Seriously, a C# developer should be able to understand at least 90% or more of a VB application, even if they couldn't write it themselves. All the types and members will be the same and in many cases all that needs doing is adding the semicolon. You should read the code carefully and have a go yourself. You can always ask if you have specific issues.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: [2.0] Zip and UNzip

    Ok.Now I got this method
    VB Code:
    1. using System.Text;
    2. using System;
    3. using System.Collections.Generic;
    4. using System.IO;
    5. using System.Collections;
    6. using java.util.zip;
    7. using java.util;
    8. using System.Data;
    9. namespace WindowsApplication2
    10.     {
    11.  
    12.  
    13.     public class ZipUnzip
    14.     {
    15.      
    16.         public string  ZipFolder(string  sSourceFoldername,string sDestinationFile)
    17.         {
    18.             try
    19.             {
    20.                 string strFile;
    21.                 string sFilename;
    22.                 FileStream objFile;
    23.                 objFile = File.Create(sDestinationFile);
    24.                 objFile.Close();
    25.                 java.io.FileOutputStream fos = new java.io.FileOutputStream(sDestinationFile);
    26.                 java.util.zip.ZipOutputStream zos = new java.util.zip.ZipOutputStream(fos);
    27.                // ZipOutputStream zipFile = new ZipOutputStream(new java.io.FileOutputStream(objFile.Name));
    28.                //// zipFile.setLevel(6);
    29.                 foreach (FileInfo f in new DirectoryInfo(sSourceFoldername).GetFiles("*.*",SearchOption.AllDirectories))
    30.                 {
    31.                     java.io.FileInputStream fis = new java.io.FileInputStream(f.FullName);
    32.                     // File name format in zip file is:
    33.                     // folder/subfolder/filename
    34.                     // Let's delete drive name and replace '\' with '/':
    35.                     //java.util.zip.ZipEntry ze = new java.util.zip.ZipEntry(f.FullName.Replace('\\', '/'));
    36.                     //java.util.zip.ZipEntry ze = new java.util.zip.ZipEntry(f.Length);
    37.                     sFilename = f.FullName;
    38.                     strFile = sFilename.Substring(sFilename.LastIndexOf("/") + 1);
    39.                     java.util.zip.ZipEntry ze = new java.util.zip.ZipEntry(strFile);
    40.                     zos.putNextEntry(ze);
    41.                     sbyte[] buffer = new sbyte[1024];
    42.                     int len;
    43.                     while((len = fis.read(buffer)) >= 0)
    44.                     {
    45.                         zos.write(buffer, 0, len);
    46.                     }
    47.                     zos.closeEntry();
    48.                     fis.close();
    49.                 }
    50.                 zos.close();
    51.                 fos.close();
    52.  
    53.             }
    54.  
    55.  
    56.             catch(Exception ex)
    57.             {
    58.                 return ex.Message;
    59.  
    60.             }
    61.             return "Success";
    62.         }
    63.  
    64.         public static void CopyStream(java.io.InputStream from, java.io.OutputStream to)
    65.         {
    66.             sbyte[] buffer = new sbyte[8192];
    67.             int got;
    68.             while ((got = from.read(buffer, 0, buffer.Length)) > 0)
    69.                 to.write(buffer, 0, got);
    70.         }

    and I call this method
    VB Code:
    1. private void button2_Click(object sender, EventArgs e)
    2.         {
    3.          if (FBrowse.ShowDialog() == DialogResult.OK)
    4.          {
    5.            
    6.              ZipUnzip c=new ZipUnzip();
    7.              //c.ZipFolder (new DirectoryInfo(FBrowse.SelectedPath()));
    8.              MessageBox.Show(c.ZipFolder(FBrowse.SelectedPath, @"c:\test.zip"));
    9.            
    10.              //c.CreateZipFile(new DirectoryInfo(FBrowse.SelectedPath), @"c:\test.zip");
    11.             }
    12.         }


    It is doing the zipping correctly.When I unzip the
    file,it is giving the oldfile path and extracting the
    like the OLD folder Format.How to solve this problem
    Please mark you thread resolved using the Thread Tools as shown

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width