This project is read-only.

IsZipFile method for COM

Sep 8, 2009 at 1:50 PM

Hi Cheeso,

Any chance of having the IsZipFile methods available to COM clients or variation of? I think because its shared its not exposed

I want to use - Public Shared Function IsZipFile ( fileName As StringtestExtract As Boolean) As Boolean (none of the overloads are available)

I can't create my own implementation within my app (catching errors on the way) as I don't have access to a Stream.Null to dump the entries on extract

Hope you can work your magic or suggest an alternative





Sep 8, 2009 at 5:52 PM

Hmm, I'll have to think about it.

Sep 8, 2009 at 9:01 PM

I don't think so.

COM uses instances, and allows you to invoke methods on those instances. The easiest way to do what you want would be to create a wrapper class in .NET that did nothing but invoke the static IsZipFile method on the Ionic.ZipFile class. Stream.Null is also a static property, so also inaccessible to COM clients.

What is the COM environment you're working in? 


Sep 9, 2009 at 2:48 AM

Here;s a wrapper class that does what you need.

// ZipHelper.cs
// ------------------------------------------------------------------
// a wrapper class that allows COM clients to call static methods exposed by the Ionic.Zip assembly.
// Build this with:
//       csc.exe  /debug+ /target:library /R:"c:\program files\dino chiesa\DotNetZip Tools v1.9\Ionic.Zip.dll" ZipHelper.cs
// Before using this component from COM, you must register it with:
//       regasm /codebase ZipHelper.dll 
// ------------------------------------------------------------------
// Copyright (c) 2009 by Dino Chiesa
// All rights reserved!
// ------------------------------------------------------------------

using System;
using System.Reflection;
using System.Security;
using System.Runtime.CompilerServices;
using Interop=System.Runtime.InteropServices;

using Ionic.Zip;

// Setting ComVisible to false makes the types in this assembly not visible 
// to COM components.  If you need to access a type in this assembly from 
// COM, set the ComVisible attribute to true on that type.
[assembly: Interop.ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Interop.Guid("cd7f0cd4-d916-4964-8bc0-688ece38ffba")]

namespace Ionic.Wrappers

    public class ZipHelper
        public bool IsZipFile(string filename)
            return ZipFile.IsZipFile(filename);

        // Cannot use "overloaded" Method names in COM interop.
        // So, use a unique name. 
        public bool IsZipFileWithExtract(string filename)
            return ZipFile.IsZipFile(filename, true);

You need to have the Ionic.Zip.dll installed in the GAC for this to work.  (run this command:   gacutil -i Ionic.Zip.dll) 

And here's a javascript client that uses the wrapper class.

        var obj = new ActiveXObject("Ionic.Wrappers.ZipHelper");
        var result = obj.IsZipFile("TestZipHelper.js");
        WScript.Echo("result : " + result);

        result = obj.IsZipFileWithExtract("");
        WScript.Echo("result : " + result);
    catch (e2)
        WScript.Echo(e2.number + ": " +;

Sep 9, 2009 at 4:19 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Sep 9, 2009 at 4:39 AM

I decided to implement the wrapper class in DotNetZip. 

The class name is Ionic.Zip.ComHelper.  It exposes a method called IsZipFile(), that accepts a string.

This change is in v1.9.0.3 of the library.


Sep 9, 2009 at 11:27 PM

Thanks Cheeso you're are star!

Works perfectly!

I really appreciate you added the wrapper within your libary. I didn't want to have to create and maintain my own version. I believe it also enhances your library. looking forward to further COM enhancements.

In answer to your question I'm currently using vbscript in WSH and SQL Server Data Transformation Services - I know time to upgrade but life is never that easy

Some things i noticed on

the DotNetZipLib-Runtime-v1.9.msi once run is titled 1.8 and installs to 1.8.

Within the chm on the ComHelper documentation the functions ReturnValue is "[Missing <returns> documentation for "......"

perhaps a couple of tweaks for your next release

Thanks again Matt


Sep 10, 2009 at 4:54 AM

Matt, thanks for the feedback and bug reports.

I'll fix those things.


Sep 10, 2009 at 5:16 AM

ps: I tried using that wrapper, and it worked, but it was too much of a hassle to set up.   It needed to be registered, and The Ionic.Zip.dll needed to be in the GAC, and all that was just a hassle.  So I decided it would be worth it just having the helper class inside the library.   I'm glad you like it.