Telerik Forums
Telerik Document Processing Forum
1 answer
292 views
Hi,

I am searching for a way to export out a word document from my c# wpf application. I have a documentviewer that has a generated document. Does the words processing control allow this?

many thanks,

Rob
Alex
Telerik team
 answered on 11 Jun 2014
1 answer
304 views
Hi,
I am working with some log files I generate with another application.  My intention is to archive them and then delete the large log file and have it stored in a compressed format for later access.    This works when I use ZipArchiveMode.Create.   Where this falls apart is that if I delete the file after I have added it to the archive, and then run the program again, it is not keeping the old entries in the archive - since I am using "Create".  I also wanted to save time that if the file I wanted to add was already in the archive, it would skip adding it.  A query against the Entries property of the ZipArchive does not seem to work when the mode is set to Create - it might work for the first time I ask, but once I add a file I get an error.  I then attempted to use ZipArchiveMode.Update, but then I received and ObjectDisposedException {"Cannot access a closed Stream."}.

I am using the code found in this post
http://www.telerik.com/forums/zip-content-of-a-folder-into-an-encrypted-zip-file
to add the existing files to the archive.

So I'm not sure if I am using the ZipArchive incorrectly, or I need to do it a different way, but help and guidance would be appreciated.  I can create a demo app if needed.

Thanks,
Chris
Andrey
Telerik team
 answered on 11 Jun 2014
2 answers
390 views
I'm trying to compress and decompress file with ZipLibrary. But it doesn't works. Can anybody help me?

 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

Stalin Vladimir
Top achievements
Rank 1
 answered on 15 Apr 2014
1 answer
93 views
Hello,

I used RadAsyncUpload control to accept a upload zip file. My zip file contains text delimiter files.  I am able to unzip it to a temporary directory, but if I try again with the same zip file I get error something like "...because it is being used by another process." (at line 17)

Below is my method to unzip:
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.    }


Please help,

Thanks,
Sam
Angel Petrov
Telerik team
 answered on 14 Apr 2014
3 answers
385 views
I have an application where I have been using the following code:

       using (ZipPackage zipPackage = ZipPackage.Open(stream, FileAccess.Read))
                    {
                        foreach (ZipPackageEntry file in zipPackage.ZipPackageEntries.ToList())
                        {
                            if (file.FileNameInZip.Equals("nsData.json"))
                            {
                                StreamReader streamReader = new StreamReader(file.OpenInputStream());
                                string jsonString = streamReader.ReadToEnd();
                            }
                       }
                 }

and it works as expected.

I have now tried to convert it to using ZipArchive instead, but I am having some problems.

I use the following code:

  using (ZipArchive archive = new ZipArchive(stream,ZipArchiveMode.Read, false, null))
                    {
                        System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();

                        ZipArchiveEntry entry = archive.GetEntry("nsData.json");
                        if (entry != null)
                        {
                            Stream entryStream = entry.Open();
                            StreamReader reader = new StreamReader(entryStream);
                            string content = reader.ReadToEnd();


                        }
            }

And when it comes to the last line it gives the following exception:

{Telerik.Windows.Zip.InvalidDataException: Invalid block length
   ved Telerik.Windows.Zip.DeflateDecompressor.DecodeBits()
   ved Telerik.Windows.Zip.DeflateDecompressor.DecodeUncompressedBlock(Boolean& endOfBlock)
   ved Telerik.Windows.Zip.DeflateDecompressor.CheckDecodeState()
   ved Telerik.Windows.Zip.DeflateDecompressor.Decode()
   ved Telerik.Windows.Zip.DeflateDecompressor.Inflate(Byte[] bytes, Int32 offset, Int32 length)
   ved Telerik.Windows.Zip.DeflateDecompressor.ProcessTransform(Boolean finalBlock)
   ved Telerik.Windows.Zip.DeflateTransformBase.TransformBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount, Byte[] outputBuffer, Int32 outputOffset)
   ved Telerik.Windows.Zip.OperationStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   ved Telerik.Windows.Zip.CompressedStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   ved System.IO.StreamReader.ReadBuffer()
   ved System.IO.StreamReader.ReadToEnd()
   ved NstPortalUCSL.ViewModel.ViewModelHandlers.DataSourceHandler.DataSouceHandler.<>c__DisplayClassb.<InitDataSources>b__8(Object sender, GetAllNstInstancesCompletedEventArgs args)
   ved NstPortalUCSL.NstPortalWsSvc.NstPortalWsClient.OnGetAllNstInstancesCompleted(Object state)}


I would be wery thankfull if you could explain to me what I am doing wrong.

Andrey
Telerik team
 answered on 04 Apr 2014
1 answer
116 views
Hi, i am ziping some .pdf files to after download, when I run at VS2010 the zip was create correct, but when deploy at server the zip was create with 1kb, the WinRar open and show an empty zip file. I don´t receive any error. If I create a small file(10MB) work well, the zip have about 70MB. But at production should be create zips with 1GB or more.

I tried in 2 servers, both with 8GB ram and Win 2008 64 bits.

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)


The ArqsPDF is a ArrayList with filenames
Maria Ilieva
Telerik team
 answered on 18 Mar 2014
2 answers
70 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.3K+ 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
103 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
852 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
Narrow your results
Selected tags
Tags
+? more
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?