How to call a static method from a class method RRS feed

  • Question

  • I'm trying to use Shell32 functions from my class. I have:

    public void ZipFile()
         var zipfile = "my.zip";
         var zipFile = (Shell32.Folder)Shell.NameSpace(zipFilePath);
         zipFile.CopyHere(targetFilePath, 4+16+512+1024+8192);

    However I get an error on the call to Shell.NameSpace:

    Error 1 An object reference is required for the non-static field, method, or property 'Shell32.IShellDispatch5.NameSpace(object)' 

    What should I do to resolve the error?

    Friday, April 8, 2016 2:41 PM


  • The compiler tells you, that NameSpace is not static so you cannot call it directly on the class. You need an Instance of the class first.

    So maybe you want to try this:

            public void ZipFile()
                var shell = new Shell32.Shell();
                var zipfile = "my.zip";
                var zipFile = shell.NameSpace(zipFilePath);
                zipFile.CopyHere(targetFilePath, 4 + 16 + 512 + 1024 + 8192);
    At least that can be compiled if the variables are defined.

    • Marked as answer by G Britton Friday, April 8, 2016 8:06 PM
    Friday, April 8, 2016 5:36 PM