login about faq

I am using ChilkatDotNet4.dll (ver 9.4.1.0) and the following code returns null value

    public static string CompressToHexString(string oData)
    {
        return Zip.AppendUnicode("XX", oData).CopyToHex();
    }

The error logged for this, as far as I can tell, is: "Must be an entry in an open archive."

Searched the web for this error message and found nothing. Suggestions/Comments would be greatly appreciated.

Zip is a property that is returned as such:

private Chilkat.Zip z;
public Chilkat.Zip Zip {
get {
      if (z == null) {
          z = new Chilkat.Zip();
          z.UnlockComponent("<Unlock Code>");
      }
      return z;
    }
}

asked Jul 22 '14 at 18:03

drryu's gravatar image

drryu
16112

edited Jul 24 '14 at 09:42


I cannot really try with the latest version, as the AppendUnicode method does not exist in the latest version, as far as I can tell. We have a license for the 9.4.1.0 version and don't know if we can use the newest version.

I am getting the ZipEntry from the following call successfully:

ZipEntry ze = Zip.AppendUnicode("XX", oData);

but when I call

ze.CopyToHex();

The LastErrorText field has the following error: "Must be an entry in an open archive."

link

answered Jul 23 '14 at 12:19

drryu's gravatar image

drryu
16112

If you have a license for the Chilkat libraries at all, then you have a license for the latest version. The AppendString method might work for Unicode?

Even for 9.4.x, I was interested in the Zip object (which we can't tell from your snippet how it was instantiated, or if a ZIP file was opened/created), not the ZipEntry object (which we can tell from your snippet comes from the AppendUnicode call).

Have you called Zip.NewZip or Zip.OpenZip before you try to call AppendUnicode?

Lastly, please post the entire contents of the LastErrorText property after calling AppendUnicode.

(Jul 23 '14 at 16:01) jpbro ♦

First, you might want to try with the latest version of the library to see if that makes a difference.

If not, you should also be testing each step of the process for success/failure, and if a step fails, then you should get the contents of the LastErrorText property and post them here for review (in <pre></pre> tags).

Here's an example of the above (in VB6, but it should be easily translatable to your language):

Public Function CompressToHexString(ByVal p_Data As String) As String
   Dim lo_Entry As ChilkatZipEntry2

Set lo_Entry = Zip.AppendString("FileName", p_Data)
   If lo_Entry Is Nothing Then
      MsgBox "Error: " & Zip.LastErrorText
   Else
      CompressToHexString = lo_Entry.CopyToHex
   End If
End Function

All of that said - the error seems to indicate that you don't have an open zip file to work with. Have you created the object held in Zip, and also opened an archive using either the NewZip or OpenZip methods yet?

link

answered Jul 22 '14 at 18:46

jpbro's gravatar image

jpbro ♦
1.1k2618

edited Jul 22 '14 at 18:46

I'm not sure why you don't want to answer my question re: calling OpenZip/NewZip on the Zip object, or why you refuse to post the full contents of the LastErrorText property, so this will be my last attempt to help.

By the looks of the code snippet you've posted re: your ChilkatZip object instantiation (and judging by the portion of the error that you've provided), you have not called either OpenZip (on an existing ZIP file) or NewZip (to start a new zip file) before you are trying to append data to your zip object/file.

link

answered Jul 24 '14 at 17:08

jpbro's gravatar image

jpbro ♦
1.1k2618

The AppendString replaces AppendUnicode. In VB.NET or C#, when a string is passed as an argument to any method, it's a string object -- and it really makes not sense to say that it's "Unicode" or anything else. It's just a string. The need to indicate the charset when a "string" is passed to a method only applies when the programming language is such that a "string" is simply a sequence of bytes, possibly null-terminated. In that case, it's important to indicate in some way how those bytes should be interpreted to arrive at the characters they represent. In C# or VB.NET, there is never such a need because strings are objects.

The CopyToHex method returns the compressed contents of the zip entry. In older versions of Chilkat Zip, it was possible to add a string to the zip object (not yet producing a zip file, but simply adding an entry to the zip object in memory), and then retrieve the compressed contents via CopyToHex. In newer versions of Chilkat Zip, this is no longer possible. It is only possible after Chilkat.Zip.OpenZip is called (meaning the .zip must pre-exist), or after calling Chilkat.Zip.WriteZip or Chilkat.Zip.WriteToMemory. (There are technical reasons why this happened, and it has to do with supporting different compression methods for ZipX.) If the need is to simply compress a string using the deflate compression algorithm, then it would be better to use the Chilkat.Compression class.

link

answered Jul 24 '14 at 19:16

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

Sorry for late reply. I am colleque of drryu. We tried to use openZip or NewZip before but CopyToHex() would return null. But I tried it today and it is working fine. Wired. Thanks for help though.

link

answered Jul 25 '14 at 11:25

Faizullah's gravatar image

Faizullah
11

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×87
×3
×1

Asked: Jul 22 '14 at 18:03

Seen: 1,053 times

Last updated: Jul 25 '14 at 11:25

powered by OSQA