Advertisement

05.15.2008 at 03:04PM PDT, ID: 23406851
[x]
Attachment Details

System.IO.File.Move Error Access to the path is denied.

Asked by amirhpr in C# Programming Language

Tags: C#, Using System.IO.Directory.CreateDirectory and System.IO.File.Move, Access to the path is denied.

On my Windows service written in C#, there is a method that makes an app domain and then loads some assemblies for that app domain (all of these are inside a thread).
Im trying to add the following functionality:
1.      Check to see if assemblies are loaded?
2.      If yes then unload the app domain
3.      Create a directory using System.IO.Directory.CreateDirectory
4.      Back up DLL assemblies into the backup directory using System.IO.File.Move
5.      Copy over the new DLL assemblies using the System.IO.File.Move
6.      Reload the app domain

Only step 4 is not working and Im getting the Access to the path is denied. in the Application event where I log the exceptions.
I cannot rename, delete, or move the DLL assemblies.
I used the sysinternal procexp to make sure when I try to move the DLLs they are not using by anyone and still I cannot move them.

I wonder if anyone knows the right way of checking the securities and permissions so this can be done (I mean programmatically).
In other words, if you were I, how do you write your code?
Here is mine (please copy and paste into VS, the text format is changed here):

Assembly[] allAssemblies;
                              allAssemblies = appDomain.GetAssemblies();
                              // Check if a PARSER_*.dll assembly is loaded
                              foreach (Assembly assemblyFile in allAssemblies)
                              {
                                    string assemblyName = assemblyFile.FullName;
                                    if (assemblyName.Contains("PARSER"))
                                          isParserModuleLoaded = true;
                              }
                              // If parser assembly is already loaded then unload the app domain CopilotParserController
                              if (isParserModuleLoaded)
                                    AppDomain.Unload(appDomain);

                              System.IO.DirectoryInfo sourceDir = new DirectoryInfo(Application.StartupPath + "\\PhoneHomeServicesUpdate");
                              System.IO.Directory.CreateDirectory(Application.StartupPath + "\\PARSER Modules Backup");
                              System.IO.DirectoryInfo backupDir = new DirectoryInfo(Application.StartupPath + "\\PARSER Modules Backup");
                              FileInfo[] destinFileList = dir.GetFiles("PARSER_*.*");
                              // Make backup
                              foreach (FileInfo destinFile in destinFileList)
                                    try
                                    {
                                          CommonLoggingProvider.LogMessageDebug("Make backup to {0}", backupDir.FullName);
                                          System.IO.File.Move(destinFile.FullName, backupDir.FullName + "\\" + destinFile.Name);
                                    }
                                    catch (Exception ex)
                                    {
                                          CPDataService.stats.Errors++;
                                          CommonLoggingProvider.LogEventWarning(ex.Message);
                                          ErrorReporter.ReportException(ex, "Copilot Data Service <CPDataService.ExecuteParsers> exception");
                                    }
Start Free Trial
[+][-]05.15.2008 at 03:19PM PDT, ID: 21578432

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.16.2008 at 07:27AM PDT, ID: 21583011

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.16.2008 at 01:32PM PDT, ID: 21586216

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.16.2008 at 11:14PM PDT, ID: 21588154

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: C# Programming Language
Tags: C#, Using System.IO.Directory.CreateDirectory and System.IO.File.Move, Access to the path is denied.
Sign Up Now!
Solution Provided By: amirhpr
Participating Experts: 2
Solution Grade: A
 
 
[+][-]05.18.2008 at 11:34AM PDT, ID: 21593544

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.18.2008 at 01:32PM PDT, ID: 21593940

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]05.19.2008 at 06:57AM PDT, ID: 21597804

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628