0

Archiving is working on a remote desktop (coworker) in the office and on the website. I have tested it.

I am writing a service and I need this inside it also. This is not working on my machine, I work remotely and am connected via VPN. The user logged in on this machine belongs to the domain.

Now, before zipping, I am impersonating with a special user account. If I don't do this then this will not even work on the website.

Following is the exception that I am getting. How can i fix it?

System.IO.FileLoadException was caught
  Message=Could not load file or assembly 'ICSharpCode.SharpZipLib, Version=0.85.3.365, Culture=neutral, PublicKeyToken=1b03e6acf1164f73' or one of its dependencies. Access is denied.
  Source=Project.Helpers
  FileName=ICSharpCode.SharpZipLib, Version=0.85.3.365, Culture=neutral, PublicKeyToken=1b03e6acf1164f73
  FusionLog==== Pre-bind state information ===
LOG: User = Unknown
LOG: DisplayName = ICSharpCode.SharpZipLib, Version=0.85.3.365, Culture=neutral, PublicKeyToken=1b03e6acf1164f73
 (Fully-specified)
LOG: Appbase = file:///C:/Users/UserPC/Documents/DATA/Projects/ProjectHelperApps/ProjectHelper/TestResults/UserPC_UserPCJ-LAPTOP 2012-08-03 15_50_57/Out
LOG: Initial PrivatePath = NULL
Calling assembly : Project.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\UserPC\Documents\DATA\Projects\ProjectHelperApps\ProjectHelper\TestResults\UserPC_UserPCJ-LAPTOP 2012-08-03 15_50_57\Out\Project.Helpers.Tests.DLL.config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: ICSharpCode.SharpZipLib, Version=0.85.3.365, Culture=neutral, PublicKeyToken=1b03e6acf1164f73
LOG: Attempting download of new URL file:///C:/Users/UserPC/Documents/DATA/Projects/ProjectHelperApps/ProjectHelper/TestResults/UserPC_UserPCJ-LAPTOP 2012-08-03 15_50_57/Out/ICSharpCode.SharpZipLib.DLL.
ERR: A fatal error occurred when retrieving next codebase for download (hr = 0x80070005).

  StackTrace:
       at Project.Helpers.IO.ZipUtility.ZipFiles(String toArchivePath, String destDir, String archiveName, String password, Boolean isDir)
       at Project.Helpers.IO.FileSystem.ArchiveDirectory(String dirToArchive, String destDir, String archiveName)
  InnerException:

Here is the archive method:

public bool ArchiveDirectory(string dirToArchive, string destDir, string archiveName)
        {
            bool ok = false;

            if (!String.IsNullOrWhiteSpace(dirToArchive) &&
                    !String.IsNullOrWhiteSpace(destDir) &&
                    !String.IsNullOrWhiteSpace(archiveName) &&
                    DirectoryExists(dirToArchive))
            {
                ok = true;
                //create destination directory
                if (!DirectoryExists(destDir))
                    ok = CreateDirectory(destDir);
            }

            if (ok)
            {
                //Archive Name should have .ZIP extension, if not, add it
                if (!archiveName.ToLowerInvariant().Contains(".zip"))
                    archiveName = archiveName + ".ZIP";

                //Check that the Zip file already exists, if it does then delete it
                if (FileExists(Path.Combine(destDir, archiveName)))
                    ok = FileDelete(Path.Combine(destDir, archiveName));
            }

            if (ok)
            {
                //Start Impersonation
                _impersonate.DoImpersonate();

                //Using ZipUtility Class to Zip Directory
                try
                {
                    ZipUtility.ZipFiles(dirToArchive, destDir, archiveName, "", true);
                }
                catch (SystemException ex)
                {
                    ok = false;
                }
                //end impersonation
                _impersonate.Dispose();
            }

            if (ok)
            {
                //double check that the archived directory exists
                ok = FileExists(Path.Combine(destDir, archiveName));
            }

            return ok;
        }

Please note that impersonation is working as CreateDirectory, FileExists and FileDelete are working without any problem. These 3 methods impersonate first before performing the associated action.

Thanks for looking into it!

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
learning...
  • 3,104
  • 10
  • 58
  • 96
  • I have tested DotNetZipLib on my local machine and it is resulting in the same error also. This is working perfectly on my coworkers machine just like above. Could not load file or assembly 'Ionic.Zip, Version=1.9.1.8, Culture=neutral, PublicKeyToken=edbe51ad942a3f5c' or one of its dependencies. Access is denied. – learning... Aug 04 '12 at 07:20

2 Answers2

1

Solved the problem by applying following:

  1. Gave ownership of C to admin group and drilled it down to the file level instead of the installer.
  2. Applied full control permission on C for admin group and drilled it down to the file level
learning...
  • 3,104
  • 10
  • 58
  • 96
1

Clean the folders temporary in the C: \ Windows \ Microsoft.NET \ Framework \ ... \ Temporary ASP.NET Files.

Hope this can help.

Yusan Susandi
  • 229
  • 2
  • 7
  • 21