-1
I need to compress all of my E folders: But when I try with this code, I get this access exception. I’m new to programming and I’m trying to learn how to do things right. I am using dotnetzip to compress the directories inside E: Some parts of the code are copied, I know that... but it was because all the solutions I tried myself didn’t work, so I just tried to implement things that seemed to work for other people
I’ve tried some other solutions to solve the problem answered here in the same Stack. How to add a manifesto to the project that uses requeireAdministrator to run the project, and insert an Accessrule access control rule to modify the security of E: One thing I notice when I do this is that my user has their permissions removed from sub-E files and directories: But without this access rule, the same exception still exists. I don’t know if I’m implementing it wrong...
Well, thank you for your attention to those who read so far! I’ll leave down here what I want to do with the program and the bug catch:
try
{
ZipFile zip = new ZipFile();
zip.AddDirectory(@"E:\");
zip.Save(@"C:\Users\vitorbento\Desktop\backup.zip");
Console.WriteLine("Compactação concluída");
Console.WriteLine("Done.");
}
catch (UnauthorizedAccessException)
{
FileAttributes attr = (new FileInfo(DirectPath)).Attributes;
Console.Write("UnAuthorizedAccessException: Unable to access file. ");
if ((attr & FileAttributes.ReadOnly) > 0)
Console.Write("The file is read-only.");
}
Have you tried running the application as an administrator? (to debug, visual studio should open with administrator as well)
– Thiago Araújo
I tried to open Visual Studio as an administrator, as well as open the generated file as an administrator.
– Rockyi.exe