I need compact all the folders of my E:\ But when i try with this code, i get this access exception. I'm new on programming and are trying learn how a i can do this work. I'm using the dotnetzip for compact the directories inside E:. Some parts of the code are just copied, i know that... but i'm trying learn how to do work.
I already tried some others solution for solve the problem answered here. Like add a manifest to the project who requeireAdministrator permissions to run and insert a Access Control Rule to modify the security of E:\ Something that i notice when do this is my user have permissions removed from the subfiles and directories of E:\ But without this access rule the same exception keep existing.
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.");
}