Given these 2 files: c:\folder1\test.txt and c:\folder2\test.txt
What is the best way to create a zip file (c:\test.zip) and add the 2 files and include the directory structure, using .Net 4.5 System.IO.Compression on VB.NET?
Thanks.
Given these 2 files: c:\folder1\test.txt and c:\folder2\test.txt
What is the best way to create a zip file (c:\test.zip) and add the 2 files and include the directory structure, using .Net 4.5 System.IO.Compression on VB.NET?
Thanks.
the answer was located on the site here
.NET GZipStream compress and decompress
public static bool Test()
{
string sample = "This is a compression test of microsoft .net gzip compression method and decompression methods";
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
byte[] data = encoding.GetBytes(sample);
// Compress.
GZipStream hgs;
byte[] cmpData;
using(MemoryStream cmpStream = new MemoryStream())
using(hgs = new GZipStream(cmpStream, CompressionMode.Compress))
{
hgs.Write(data, 0, data.Length);
cmpData = cmpStream.ToArray();
}
using(MemoryStream decomStream = new MemoryStream(cmpData))
using(hgs = new GZipStream(decomStream, CompressionMode.Decompress))
{
hgs.Read(data, 0, data.Length);
}
string sampleOut = encoding.GetString(data);
bool result = String.Equals(sample, sampleOut);
return result;
}