Telerik Forums
Telerik Document Processing Forum
2 answers
84 views
For 1 specific file I get wrong data after char 813302

It doesnt seem related to the size of the file, larger files work fine.

I do have an example that reproduces this, but so far I have only been able to reproduce it with sensitive data.

After compressing/decompressing I get:
<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" />

In the original it said:
<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" />

So the two Field are swapped, also there is some strange tag RowAANdh in it that I cant explain, it looks like the RowGroup="88"

The code I use is below

The output I get is:

Loading file: ..\..\PowerBrowser.gpf
Length original: 5691434
Length after compress/decompress: 5657083
Index first difference: 813302 



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");
        }
    }
}











Andrey
Telerik team
 answered on 17 Mar 2014
3 answers
1.5K+ views
Hello,
 
    I tried to compress a byte array in C# using Zip Library, but it seems I a missing something because every time I call compress sending a byte array parameter, I cannot decompress it correctly please see code as follows to compress

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());
       }

and the following is how I decompress it back and the function will return byte array as follows:

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();
 
        }

Thanks,

Levi
B
Top achievements
Rank 2
 answered on 13 Mar 2014
1 answer
113 views
Where can I find the documentation for SpreadProcessing?

http://www.telerik.com/help/wpf/introduction.html Does not have anything yet.

I'm a user of UI for WPF.

Thank you.
Petya
Telerik team
 answered on 05 Mar 2014
12 answers
925 views
Hi

I not figure out how to save a (large) binary file to disk from a zip-Package back to a file.

Thanks for help
Henry
Top achievements
Rank 1
 answered on 28 Jan 2014
15 answers
543 views
Hi,

I'm trying to zip a PDF document but something goes wrong.
This is the code I use
MemoryStream compressedStream;
ZipPackage package;
MemoryStream sourcestream = new MemoryStream();
 
RadDocument document = this.CreateDocument(TileViewmodel);
this.PrepareDocument(document);
PdfFormatProvider provider = new PdfFormatProvider();
provider.Export(document, sourcestream);
 
compressedStream = new MemoryStream();
package = ZipPackage.Create(compressedStream);
package.AddStream(sourcestream, "WindowPeristedData");

Right before I add a PDF file of 7MB, the length of the compressedStream variable is 22 (bytes I think). After the AddStream the size is 142. I don't think that is correct. The sourcestream I add has a lenghth of 7.085.200. You can't zip an 7MB file into a 142 byte file.

What am I doing wrong?

Kind regards, 

Jan Buskens. 
JIG
Top achievements
Rank 1
 answered on 24 Dec 2013
3 answers
161 views
Hi,

is it possible to encrypt and decrypt a ZipLirbary which is created with the RadZipLirbary? How to?

Thanks
best Regards
Rene
Kiril Vandov
Telerik team
 answered on 29 Nov 2013
1 answer
163 views
Hey together,

I've got a little problem with the ZipPackage in the Telerik.Windows.Zip library.

I'm developing in a Silverlight environment (Silverlight Business Application). On the server side I zip a user specified amount of files (which are stored in a Microsoft SQL database).

At first a little code snippet:

MemoryStream ms = new MemoryStream();
byte[] zip = null;
 
using ( ZipPackage zipfile = ZipPackage.Create(ms) ) {
    foreach ( var kvp in files ) {
        zipfile.AddStream(new MemoryStream(kvp.Value), kvp.Key, ZipCompression.Default, DateTime.Now);
    }
 
    zip = new byte[(int) ms.Length];
    ms.Seek(0, SeekOrigin.Begin);
    ms.Read(zip, 0, (int) ms.Length);
    ms.Dispose();
}
 
return zip;

As you can see, I store the ZipPackage in a MemoryStream. After the "using" code block I return the content of the MemoryStream (ms) back to the client side of my application (the above procedure is called due to an InvokeOperation). On the client side, the returned byte array will be stored under a user specified filename in the local file system. This works really proper, but after opening the stored zip file, I see, that filenames (containing german umlauts like ä, ö, ü) are not well encoded.

For example:
A filename in the database is called "Aufsätze.docx". After storing this file with this filename in the zippackage and save the file on my hard disk, the filename is called "Aufs+ñtze.docx".

I've tried a lot with encoding ... default, utf8, etc. but nothing works.

Do you have an idea, what else I can do or try? If you need more information or code snippets, please let me know it.

Kind regards,
Chris
Kiril Vandov
Telerik team
 answered on 01 Nov 2013
3 answers
207 views
Hi,

i got a question using the ZipLibrary.

We got a .zip file with about 20 files zipped.

Some of the filenames contains german umlauts like ä,ö,ü ....

Now, when using the ziplibrary the filenames which got german umlauts are incorrect.

Here is the function to get the files.

Dim fname As String = System.IO.Path.Combine(System.Configuration.ConfigurationManager.AppSettings("GlobalUploadPath"), Filename)
            Dim fs As New FileStream(fname, FileMode.Open, FileAccess.Read)
 
            Try
 
                Using package = ZipPackage.Open(fs)
 
                    Dim allEntries As List(Of ZipPackageEntry) = package.ZipPackageEntries
                    For Each entry As ZipPackageEntry In allEntries
                        Dim filename As String = System.IO.Path.GetFileNameWithoutExtension(entry.FileNameInZip.ToLower)
 
                  -->> wrong filenames in entry.FileNameInZip
 
                        If tableList.Contains(filename) Then
               ' Reading the Data
                        End If
 
                    Next
 
                End Using


Any hint's ?

thank you

Martin
Telerik team
 answered on 09 Aug 2013
1 answer
133 views
Hi,

we have requirement to generate zip file from list of images and allow it to download in Silverlight.
All images are stored on remote machine(\\192.168.1.7\\abc\\\abc\year\month\1234\1234.jpg).
so I have implemented functionality to get the list of images and passed it to wcf service as an argument
and it returns list of byte array.
I have implemented the below code to create the zip file from list of stream.
busyIndicator.IsBusy = true;
            if (ListPic.Count > 0)
            {
                //Save zip File
                SaveFileDialog dialog = new SaveFileDialog();
                dialog.Filter = "Zip File | *.zip";
                bool? dialogResult = dialog.ShowDialog();
                if (dialogResult == true)
                {
                    using (ZipPackage zipPackage = ZipPackage.Create(dialog.OpenFile()))
                    {
 
                        foreach (PictureFile pic in ListPic)
                        {
                            Stream picStream = new MemoryStream(pic.PictureStream);
                            zipPackage.AddStream(picStream, System.IO.Path.GetFileName(pic.PictureName),ZipCompression.Deflated,DateTime.Now);
                             
                        }
                    }
 
                     
                }
                busyIndicator.IsBusy = false;
                this.DialogResult = false;

                 
            }
            else
            {
                busyIndicator.IsBusy = false;
                this.DialogResult = false;
            }

In above code I have used to deflate compression to compress stream but it always returns the size and compression not works.
Is there any more configuration required for compression to work?

Thanks
Rahul


Tina Stancheva
Telerik team
 answered on 17 Jul 2013
3 answers
331 views
Does anyone know if the ZipPackage can accept a folder or set of folders and build a valid zip file from them? I haven't seen any examples or documentation on this.
maxscan
Top achievements
Rank 1
 answered on 21 May 2013
Narrow your results
Selected tags
Tags
+? more
Top users last month
Boardy
Top achievements
Rank 2
Veteran
Iron
Benjamin
Top achievements
Rank 3
Bronze
Iron
Veteran
ivory
Top achievements
Rank 1
Iron
Iron
Rob
Top achievements
Rank 3
Bronze
Bronze
Iron
ClausDC
Top achievements
Rank 2
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Boardy
Top achievements
Rank 2
Veteran
Iron
Benjamin
Top achievements
Rank 3
Bronze
Iron
Veteran
ivory
Top achievements
Rank 1
Iron
Iron
Rob
Top achievements
Rank 3
Bronze
Bronze
Iron
ClausDC
Top achievements
Rank 2
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?