Dear All,
How to zip and Unzip folders using J# Runtime component.
Printable View
Dear All,
How to zip and Unzip folders using J# Runtime component.
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
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
Is there anymethod avl to convert the coding into C#
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.
Ok.Now I got this method
VB Code:
using System.Text; using System; using System.Collections.Generic; using System.IO; using System.Collections; using java.util.zip; using java.util; using System.Data; namespace WindowsApplication2 { public class ZipUnzip { public string ZipFolder(string sSourceFoldername,string sDestinationFile) { try { string strFile; string sFilename; FileStream objFile; objFile = File.Create(sDestinationFile); objFile.Close(); java.io.FileOutputStream fos = new java.io.FileOutputStream(sDestinationFile); java.util.zip.ZipOutputStream zos = new java.util.zip.ZipOutputStream(fos); // ZipOutputStream zipFile = new ZipOutputStream(new java.io.FileOutputStream(objFile.Name)); //// zipFile.setLevel(6); foreach (FileInfo f in new DirectoryInfo(sSourceFoldername).GetFiles("*.*",SearchOption.AllDirectories)) { java.io.FileInputStream fis = new java.io.FileInputStream(f.FullName); // File name format in zip file is: // folder/subfolder/filename // Let's delete drive name and replace '\' with '/': //java.util.zip.ZipEntry ze = new java.util.zip.ZipEntry(f.FullName.Replace('\\', '/')); //java.util.zip.ZipEntry ze = new java.util.zip.ZipEntry(f.Length); sFilename = f.FullName; strFile = sFilename.Substring(sFilename.LastIndexOf("/") + 1); java.util.zip.ZipEntry ze = new java.util.zip.ZipEntry(strFile); zos.putNextEntry(ze); sbyte[] buffer = new sbyte[1024]; int len; while((len = fis.read(buffer)) >= 0) { zos.write(buffer, 0, len); } zos.closeEntry(); fis.close(); } zos.close(); fos.close(); } catch(Exception ex) { return ex.Message; } return "Success"; } public static void CopyStream(java.io.InputStream from, java.io.OutputStream to) { sbyte[] buffer = new sbyte[8192]; int got; while ((got = from.read(buffer, 0, buffer.Length)) > 0) to.write(buffer, 0, got); }
and I call this method
VB Code:
private void button2_Click(object sender, EventArgs e) { if (FBrowse.ShowDialog() == DialogResult.OK) { ZipUnzip c=new ZipUnzip(); //c.ZipFolder (new DirectoryInfo(FBrowse.SelectedPath())); MessageBox.Show(c.ZipFolder(FBrowse.SelectedPath, @"c:\test.zip")); //c.CreateZipFile(new DirectoryInfo(FBrowse.SelectedPath), @"c:\test.zip"); } }
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