System.IO.Compression.ZipFile UnauthorizedAccessException
Solution 1:
It seems you have misunderstood something.
backupLocation = @"C:\Backups";
you want to overwrite the directory "C:\Backups" with a file ! That's not allowed! ;-) (Access Denied)
You have to specify the path with file name.
Syntax: CreateFromDirectory(string,string)
public static void CreateFromDirectory(
string sourceDirectoryName,
string destinationArchiveFileName
)
Example:
string startPath = @"c:\example\start";
string zipPath = @"c:\example\result.zip";
ZipFile.CreateFromDirectory(startPath, zipPath);
[...]
Solution 2:
In my case I was trying to create the target directory before I started to zip the file there, but was creating the target directory as the name of the zip file, so because the empty zip file already existed (as a directory), I got the same error.