1
Answer

C# unzipping using Shell32 throws Error: The system cannot find the file specified. - HELP

Photo of Carrie Medine

Carrie Medine

14y
15.4k
1

Hello,

I am using Shell32 to unzip files, but am getting the famous vague error: 

      The system cannot find the file specified. (Exception from HRESULT: 0x80070002).

The error is thrown at the srcFlder declaration.  I did check and ensure that the file is there so error must be something else.

Here is my code - Any help is appreciated:

            DirectoryInfo di = new DirectoryInfo(@"C:\Test\");

            foreach (FileInfo fi in di.GetFiles("*.zip"))
            {
                foreach (DirectoryInfo dir in destinationDir)
                {
                    String file = fi.ToString();
                    var destinationPath = @"C:\AppName\";
                    if (!Directory.Exists(destinationPath))
                        Directory.CreateDirectory(destinationPath);

                    Shell sh = new Shell();
                    Folder destFlder = sh.NameSpace(destinationPath);
                    Folder srcFlder = sh.NameSpace(fi.FullName);
                    foreach (FolderItem F in srcFlder.Items())
                    { destFlder.CopyHere(F, null); }

                }
            }

Answers (1)

0
Photo of Jean Paul
NA 46.3k 6.2m 14y
I checked the cod by removing destinationDir.. (It was not compiling until then)
The following code is working for me and a test zip file was unzipped.

DirectoryInfo di = new DirectoryInfo(@"C:\Temp\");

            foreach (FileInfo fi in di.GetFiles("*.zip"))
            {
                String file = fi.ToString();
                var destinationPath = @"C:\Temp\AppName\";
                if (!Directory.Exists(destinationPath))
                    Directory.CreateDirectory(destinationPath);

                Shell sh = new Shell();
                Folder destFlder = sh.NameSpace(destinationPath);
                Folder srcFlder = sh.NameSpace(fi.FullName);
                foreach (FolderItem F in srcFlder.Items())
                {
                    destFlder.CopyHere(F, null);
                }
            }

Can you attach the zip file if problem persists?