Zip up files

F

Fred

I have a number of files that I need to zip up and upload to a web site.
Can anyone tell me how to create a .zip file and add files to the .zip file.
You can assume that the PC on which this program will be run will have XPPro
or Vista.

Thanks for your help
Fred
 
G

Germán Castro

Esto te va a servir:

Imports System.io.Compression
Imports system.io

//Call functions
CompimirArchivos(file1,file2)
DescompimirArchivos(file2, file1)

//ZIP files

Public Shared Sub CompimirArchivos(ByVal ArchivoEntrada As String, ByVal
ArchivoSalida As String)
Using Sourcefile As FileStream = File.OpenRead(ArchivoEntrada)
Using DestFile As FileStream = File.Create(ArchivoSalida)
Using CompStream As GZipStream = New GZipStream(DestFile,
CompressionMode.Compress)
Dim data(Sourcefile.Length) As Byte
Sourcefile.Read(data, 0, data.Length)
CompStream.Write(data, 0, data.Length)
End Using
End Using
End Using
End Sub

//UNZIP FILES

Public Shared Sub DescompimirArchivos(ByVal ArchivoEntrada As String,
ByVal ArchivoSalida As String)
Using Sourcefile As FileStream = File.OpenRead(ArchivoEntrada)
Using DestFile As FileStream = File.Create(ArchivoSalida)
Using CompStream As GZipStream = New GZipStream(Sourcefile,
CompressionMode.Decompress)
Dim data As Integer
data = CompStream.ReadByte()
While (data <> -1)
DestFile.WriteByte(CByte(data))
data = CompStream.ReadByte()
End While
End Using
End Using
End Using
End Sub
 
F

Family Tree Mike

Que? GZip <> Zip!

Germán Castro said:
Esto te va a servir:

Imports System.io.Compression
Imports system.io

//Call functions
CompimirArchivos(file1,file2)
DescompimirArchivos(file2, file1)

//ZIP files

Public Shared Sub CompimirArchivos(ByVal ArchivoEntrada As String, ByVal
ArchivoSalida As String)
Using Sourcefile As FileStream = File.OpenRead(ArchivoEntrada)
Using DestFile As FileStream = File.Create(ArchivoSalida)
Using CompStream As GZipStream = New GZipStream(DestFile,
CompressionMode.Compress)
Dim data(Sourcefile.Length) As Byte
Sourcefile.Read(data, 0, data.Length)
CompStream.Write(data, 0, data.Length)
End Using
End Using
End Using
End Sub

//UNZIP FILES

Public Shared Sub DescompimirArchivos(ByVal ArchivoEntrada As String,
ByVal ArchivoSalida As String)
Using Sourcefile As FileStream = File.OpenRead(ArchivoEntrada)
Using DestFile As FileStream = File.Create(ArchivoSalida)
Using CompStream As GZipStream = New GZipStream(Sourcefile,
CompressionMode.Decompress)
Dim data As Integer
data = CompStream.ReadByte()
While (data <> -1)
DestFile.WriteByte(CByte(data))
data = CompStream.ReadByte()
End While
End Using
End Using
End Using
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top