|
-
Jun 15th, 2005, 04:56 AM
#1
Thread Starter
Frenzied Member
Zip for VB.Net? [Resolved]
Hi there,
I have been looking for a way to zip files and directories up within vb.net.
I have heard of the CdSharp open source libraries but have been unable to get it to work. I have also heard of Xceed Zip class but that cost alot for something simple which i need to get done.
Has anyone got the zip to work? Can i make use of the in build zip in winXP?
Cheers
Last edited by dinosaur_uk; Jun 16th, 2005 at 03:05 AM.
-
Jun 15th, 2005, 05:05 AM
#2
Re: Zip for VB.Net?
If you have winzip on your machine then you could always use that (with command line arguments) to do it. Winzip has comprehensive commandline support and should work without any visible interface.
You couls call it with
VB Code:
Process.Start("Winzip.exe myfile.txt myzip.zip /args go here")
I don't live here any more.
-
Jun 15th, 2005, 05:14 AM
#3
Re: Zip for VB.Net?
you could have a look at
#ziplib
It's released under the GPL, however I haven't tried it myself.
-
Jun 15th, 2005, 05:16 AM
#4
Re: Zip for VB.Net?
Some suggestions in this thread.
-
Jun 15th, 2005, 08:08 AM
#5
Thread Starter
Frenzied Member
Re: Zip for VB.Net?
cheers...i will try the winzip route
-
Jun 15th, 2005, 08:12 AM
#6
Re: Zip for VB.Net?
I usually recommend the #zip utility when this question comes up. It's easy to use and doesn't require winzip on the user's machine.
Also, I think if the user has an unregistered version of Winzip, they may be prompted with the Evaluation Version box.
-
Jun 15th, 2005, 08:16 AM
#7
Re: Zip for VB.Net?
I think it unwise to assume anything about the destination machine that is not specifically under your control. If you know for sure that WinZip will be there then great, but otherwise...
-
Jun 15th, 2005, 10:20 AM
#8
Thread Starter
Frenzied Member
Re: Zip for VB.Net?
 Originally Posted by wossname
If you have winzip on your machine then you could always use that (with command line arguments) to do it. Winzip has comprehensive commandline support and should work without any visible interface.
You couls call it with
VB Code:
Process.Start("Winzip.exe myfile.txt myzip.zip /args go here")
The thing is that i would like to be able to change the name of the file and what i am zipping but it does not work?
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim source As String
source = "C:\Program Files\WinZip\WZZIP.EXE -rp hi.zip " & DatabasePath
Process.Start(source)
End Sub
Any ideas how to string build it up?
-
Jun 15th, 2005, 10:27 AM
#9
Thread Starter
Frenzied Member
Re: Zip for VB.Net?
Not sure if this is the right way, but i have done it via a batch file
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim source As New System.Text.StringBuilder
If IO.File.Exists(Application.StartupPath & "\run.bat") Then
IO.File.Delete(Application.StartupPath & "\run.bat")
End If
Dim sw As StreamWriter = IO.File.CreateText(Application.StartupPath & "\run.bat")
source.Append("C:\Program Files\WinZip\WZZIP.EXE -rp hi.zip " & DatabasePath)
sw.WriteLine(source.ToString)
sw.Close()
Process.Start(Application.StartupPath & "\run.bat")
IO.File.Delete(Application.StartupPath & "\run.bat")
End Sub
-
Jun 15th, 2005, 10:28 AM
#10
Thread Starter
Frenzied Member
Re: Zip for VB.Net?
I have made a temp batch file and have run it then deleted it after usage....
Anyone has a better solution?
-
Jun 15th, 2005, 10:57 AM
#11
Thread Starter
Frenzied Member
Re: Zip for VB.Net?
Oh by the way....if your command line has spaces in it ,,,you have to put " before and after the path...
Corrected code:
VB Code:
Dim sw As StreamWriter = IO.File.CreateText(Application.StartupPath & "\run.bat")
'For the winzip, we will potentially put this path into a config file.
source.Append(Chr(34) & "C:\program files\winzip\WZZIP.EXE" & Chr(34) & " -rp ")
source.Append(Chr(34) & Me.txtOutputFolder.Text)
source.Append(Date.Now.Day & "-")
source.Append(Date.Now.Month & "-")
source.Append(Date.Now.Now.Year & "-Database.zip" & Chr(34) & " ")
source.Append(Chr(34) & DatabasePath & Chr(34))
sw.WriteLine(source.ToString)
sw.Close()
Process.Start(Application.StartupPath & "\run.bat")
IO.File.Delete(Application.StartupPath & "\run.bat") 'Remove the file.
-
Jun 15th, 2005, 06:25 PM
#12
Re: Zip for VB.Net?
When calling Process.Start with one argument, you must use the file name only. If you are trying to start a process and you want to pass commandline arguments to it, you use an overload of Process.Start that takes two arguments. The first is the file name and the second is the commandline arguments.
VB Code:
Process.Start("C:\Program Files\WinZip\WZZIP.EXE", "-rp hi.zip " & DatabasePath)
-
Jan 11th, 2008, 04:34 AM
#13
Frenzied Member
Re: Zip for VB.Net? [Resolved]
-
Jan 11th, 2008, 04:36 AM
#14
Re: Zip for VB.Net? [Resolved]
Yes, that is the same code in 2003.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 11th, 2008, 04:41 AM
#15
Frenzied Member
Re: Zip for VB.Net? [Resolved]
rgr
What is the DatabasePath variable?
-
Jan 11th, 2008, 04:53 AM
#16
Re: Zip for VB.Net? [Resolved]
That is the name of the file to zip I'd assume. Just check the commandline arguments of the WZZIP.EXE by typing at the command prompt "WZZIP.EXE /?"
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 11th, 2008, 05:52 AM
#17
Frenzied Member
Re: Zip for VB.Net? [Resolved]
 Originally Posted by RobDog888
That is the name of the file to zip I'd assume. Just check the commandline arguments of the WZZIP.EXE by typing at the command prompt "WZZIP.EXE /?"
Not sure what you mean by that.
I found this
Adding Files
"The command format is:
winzip32 [-min] action [options] filename[.zip] files
where:
-min specifies that WinZip should run minimized. If -min is specified, it must be the first command line parameter.
action
-a for add, -f for freshen, -u for update, and -m for move. You must specify one (and only one) of these actions. The actions correspond to the actions described in the section titled "Add dialog box options" in the online manual.
options
-r corresponds to the Include subfolders checkbox in the Add dialog and causes WinZip to add files from subfolders. Folder information is stored for files added from subfolders. If you add -p, WinZip will store folder information for all files added, not just for files from subfolders; the folder information will begin with the folder specified on the command line.
-ex, -en, -ef, -es, and -e0 determine the compression method: eXtra, Normal, Fast, Super fast, and no compression. The default is "Normal". -hs includes hidden and system files. Use -sPassword to specify a case-sensitive password. The password can be enclosed in quotes, for example, -s"Secret Password".
filename.zip
Specifies the name of the Zip file involved. Be sure to use the full filename (including the folder).
files
Is a list of one or more files, or the @ character followed by the filename containing a list of files to add, one filename per line. Wildcards (e.g. *.bak) are allowed.
They way i followed it dosn't seem to work correctly
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Process.Start("C:\Program Files\WinZip\WZZIP.EXE", "-rp C:\Documents and Settings\toe\Desktop\WinZip\Document.zip" & "Document.txt")
End Sub
Error:
"System cannot find the find the file specified"
While trying to zip this file
("C:\Documents and Settings\toe\Desktop\WinZip\Document.txt")
Can you see what iam doing wrong?
thanks
toe
-
Jan 11th, 2008, 06:18 AM
#18
Frenzied Member
Re: Zip for VB.Net? [Resolved]
mmmm, maybe it only works with the pro version
The WinZip Command Line Support Add-On is a FREE add-on for users of WinZip Pro with a valid license.
winzip.com
-
Jan 11th, 2008, 08:48 AM
#19
Re: Zip for VB.Net? [Resolved]
As I stated in my post a few years ago, if you are trying to Zip from .Net, you can use the #Ziplib library. It is free.
http://www.icsharpcode.net/OpenSource/SharpZipLib/
-
Jan 11th, 2008, 04:19 PM
#20
Frenzied Member
Re: Zip for VB.Net? [Resolved]
This code will zip a folder of files using WinXP built in compression:
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim srcfolderString As String
Dim dstfolderString As String = "c:\ZippedFolder.zip"
'get folder to zip
Dim fbd As New FolderBrowserDialog
If fbd.ShowDialog() = Windows.Forms.DialogResult.OK Then
srcfolderString = fbd.SelectedPath
'create empty zip file
Dim fileContents() As Byte = {80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
My.Computer.FileSystem.WriteAllBytes(dstfolderString, fileContents, False)
Dim objShell As New Shell32.ShellClass
Dim objFolderSrc As Shell32.Folder
Dim objFolderDst As Shell32.Folder
Dim objFolderItems As Shell32.FolderItems
objFolderSrc = objShell.NameSpace(srcfolderString)
objFolderDst = objShell.NameSpace(dstfolderString)
objFolderItems = objFolderSrc.Items
objFolderDst.CopyHere(objFolderItems, 20)
End If
You also need to add a reference to Microsoft Shell Controls And Automation
-
Jan 11th, 2008, 06:39 PM
#21
Frenzied Member
Re: Zip for VB.Net? [Resolved]
 Originally Posted by nbrege
This code will zip a folder of files using WinXP built in compression:
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim srcfolderString As String
Dim dstfolderString As String = "c:\ZippedFolder.zip"
'get folder to zip
Dim fbd As New FolderBrowserDialog
If fbd.ShowDialog() = Windows.Forms.DialogResult.OK Then
srcfolderString = fbd.SelectedPath
'create empty zip file
Dim fileContents() As Byte = {80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
My.Computer.FileSystem.WriteAllBytes(dstfolderString, fileContents, False)
Dim objShell As New Shell32.ShellClass
Dim objFolderSrc As Shell32.Folder
Dim objFolderDst As Shell32.Folder
Dim objFolderItems As Shell32.FolderItems
objFolderSrc = objShell.NameSpace(srcfolderString)
objFolderDst = objShell.NameSpace(dstfolderString)
objFolderItems = objFolderSrc.Items
objFolderDst.CopyHere(objFolderItems, 20)
End If
You also need to add a reference to Microsoft Shell Controls And Automation
Thanks for that
What will the end user need to unzip a folder using WinXP built in compression: EG net frame work 2.0 only?
I tried your example on a new folder i placed on the desktop and got "Access to the path 'C:\Documents and Settings\toe\Desktop\New Folder' is denied."
Any ideas?
Negative0
I will check that out what you stated n your post a few years ago if i carnt use the WinXp built in compression.
thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|