Private Function Compress(data As Byte()) As Byte()
Dim result As Byte() = Nothing
Try
Using memoryStream As New MemoryStream()
Dim method As ZipCompression = ZipCompression.Deflate64
Using zipOutputStream As New ZipOutputStream(memoryStream, method)
Using writer As New StreamWriter(zipOutputStream)
writer.Write(data)
writer.Flush()
result = memoryStream.ToArray()
End Using
End Using
End Using
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Return result
End Function
Private Function UnCompress(data As Byte()) As Byte()
Dim result As Byte() = Nothing
Try
Using memoryStream As New MemoryStream(data)
Using zipInputStream As New ZipInputStream(memoryStream)
Using reader As New StreamReader(zipInputStream)
result = memoryStream.ToArray
End Using
End Using
End Using
Catch ex As Exception
End Try
Return result
End Function
01.
private
static
void
UnpackAndSaveFile(ZipPackageEntry entry,
string
destinationPath)
02.
{
03.
Stream stream = entry.OpenInputStream();
04.
var fileName = destinationPath +
"\\"
+ entry.FileNameInZip;
05.
06.
var directoryName = Path.GetDirectoryName(fileName);
07.
08.
if
(directoryName !=
null
)
09.
{
10.
if
(!Directory.Exists(directoryName))
11.
{
12.
Directory.CreateDirectory(directoryName);
13.
}
14.
15.
if
(System.IO.File.Exists(fileName))
16.
{
17.
System.IO.File.Delete(fileName);
18.
}
19.
20.
StreamReader reader =
new
StreamReader(stream);
21.
string
text = reader.ReadToEnd();
22.
File.WriteAllText(fileName, text);
23.
}
24.
}
Dim ArqZip As String = "Order.zip"
Dim Package As ZipPackage = ZipPackage.CreateFile(PathCart & ArqZip)
For Each ArqPDF In ArqsPDF
Try
Package.Add(CaminhoCart & ArqPDF)
Catch ex as exception
TextNotifi.Text = ex.Message
TextNotifi.Height = 150
TextNotifi.Show()
Exit For
End Try
Next
Package.Close(False)
<
Field
Name
=
"Datum wijziging"
Type
=
"2"
Length
=
"0"
FieldName
=
"MUT_DAT"
Hint
=
"Datum van de laatste wijziging"
RowAANdh
=
"0"
FieldName
=
"CREATOR_ID"
Hint
=
"Creator_id"
/>
<
Field
Name
=
"Datum aanmaak"
Type
=
"2"
Length
=
"0"
FieldName
=
"CREATEDATE"
Hint
=
"Createdate"
/>
<
Field
Name
=
"Datum aanmaak"
Type
=
"2"
Length
=
"0"
FieldName
=
"CREATEDATE"
Hint
=
"Createdate"
/>
<
Field
Name
=
"Datum wijziging"
Type
=
"2"
Length
=
"0"
FieldName
=
"MUT_DAT"
Hint
=
"Datum van de laatste wijziging"
RowGroup
=
"88"
/>
using System.Windows;
using System.Xml.Linq;
using System;
using System.IO;
using Telerik.Windows.Zip;
namespace TelerikTest
{
/// <
summary
>
/// Interaction logic for MainWindow.xaml
/// </
summary
>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
DataContext = this;
}
public static byte[] Compress(string text)
{
using (MemoryStream memoryStream = new MemoryStream())
{
using (ZipOutputStream zipOutputStream = new ZipOutputStream(memoryStream, ZipCompression.Deflated))
{
using (StreamWriter streamWriter = new StreamWriter(zipOutputStream))
{
streamWriter.Write(text);
//streamWriter.Flush();
}
byte[] bytes = memoryStream.ToArray();
return bytes;
}
}
}
public static string Decompress(byte[] data)
{
using (MemoryStream memoryStream = new MemoryStream(data))
{
using (ZipInputStream zipInputStream = new ZipInputStream(memoryStream))
{
using (StreamReader streamReader = new StreamReader(zipInputStream, new System.Text.UTF8Encoding()))
{
string text = streamReader.ReadToEnd();
return text;
}
}
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
MainLog.AppendText(string.Format("Loading file: {0}\n", FileTextBox.Text));
XElement xml = XElement.Load(FileTextBox.Text);
string text = xml.ToString();
MainLog.AppendText(string.Format("Length original: {0}\n", text.Length));
byte[] c = Compress(text);
string text2 = Decompress(c);
File.WriteAllText(@"..\..\OutputFromTelerikTest.gpf", text2);
MainLog.AppendText(string.Format("Length after compress/decompress: {0}\n", text2.Length));
int indexFirstDifference = -1;
for (int i = 0; i < Math.Min(text.Length, text2.Length); i++)
{
if (text[i] != text2[i])
{
indexFirstDifference = i;
break;
}
}
MainLog.AppendText(string.Format("Index first difference: {0}\n", indexFirstDifference));
MainLog.AppendText("\n");
}
}
}
private
string
Compress(
byte
[] data)
{
MemoryStream memoryStream =
new
MemoryStream();
ZipCompression method = ZipCompression.Default;
ZipOutputStream zipOutputStream =
new
ZipOutputStream(memoryStream, method);
StreamWriter writer =
new
StreamWriter(zipOutputStream);
writer.Write(data
);
writer.Flush();
return
Convert.ToBase64String(memoryStream.ToArray());
}
private
byte
[] UnCompress(
string
str)
{
MemoryStream memoryStream =
new
MemoryStream(Convert.FromBase64String(str));
ZipInputStream input =
new
ZipInputStream(memoryStream);
StreamReader reader =
new
StreamReader(input);
return
memoryStream.ToArray();
}