I am using ChilkatDotNet4.dll (ver 188.8.131.52) and the following code returns null value
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:
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 184.108.40.206 version and don't know if we can use the newest version.
I am getting the ZipEntry from the following call successfully:
but when I call
The LastErrorText field has the following error: "Must be an entry in an open archive."
answered Jul 23 '14 at 12:19
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?
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.
answered Jul 24 '14 at 17:08
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.
answered Jul 24 '14 at 19:16
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.
answered Jul 25 '14 at 11:25