Reputation: 73
I'm trying to delete all file from destBackUpFolder
, the result is all files are deleted from the folder except 1 dll file, I get a Unauthorized Exception said that access to the dll file is denied. I have tried suggestion from web by setting the file attribute to normal and delete file by file, check my permission and make sure my permission is allowed to delete file but all those method doesn't work, Why am I getting unauthorized exception even my permission is set to full control? FYI, I am using Team Foundation Server for my development version control, Is the problem here related to my TFS? Thanks in advance.
try
{
DirectoryInfo folderToBeDelete = new DirectoryInfo(destBackUpFolder);
folderToBeDelete.Delete(true);
if (Directory.Exists(backupFolder))
{
Directory.CreateDirectory(destBackUpFolder);
result = CopyFileAndFolder(backupFolder, destBackUpFolder);
if (result)
{
ErrorMsg = "Copy process Failed,Your File has rolled back to previous version";
IsErrorDetected = true;
}
}
}
catch (Exception)
{
ErrorMsg = "Error during roll up process";
IsErrorDetected = true;
}
//block of code where i trying to get my version number of the dll
Assembly _assembly = Assembly.LoadFrom(ConfigurationManager.AppSettings["DllPathForBackUp"]);
Version versionNumber = _assembly.GetName().Version;
completeVersionNumber = versionNumber.Major + "." + versionNumber.Minor + "." + versionNumber.Build + "." + versionNumber.Revision;
Upvotes: 1
Views: 1352
Reputation: 73
i was using the dll when i loaded the dll into my program with
Assembly _assembly = Assembly.LoadFrom(ConfigurationManager.AppSettings["DllPathForBackUp"]);
i change this code to
FileVersionInfo.GetVersionInfo(ConfigurationManager.AppSettings["DllPathForBackUp"]).FileVersion;
Now i dont have to load the dll into the program and get the error, Credit to @Darren Gourley, Thank you!
Upvotes: 1