System.UnauthorizedAccessException
FileStream fs = File.OpenRead(dir.ToString());
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
ZipEntry zipEntry = new ZipEntry(dir.Name);
zipEntry.DateTime = DateTime.Now;
zipEntry.Size = buffer.Length;
fs.Close();
crc.Reset();
crc.Update(buffer);
zipEntry.Crc = crc.Value;
BackupZip.PutNextEntry(zipEntry);
BackupZip.Write(buffer, 0, buffer.Length);
(Note: I use #ZipLib)
This code, is giving me troubles big time. The problem is that its throwing System.UnauthorizedAccessException. I doesn't matter wich folder im trying to use, it keeps throwing it.The folders aren't read only. How can i make this work?byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
ZipEntry zipEntry = new ZipEntry(dir.Name);
zipEntry.DateTime = DateTime.Now;
zipEntry.Size = buffer.Length;
fs.Close();
crc.Reset();
crc.Update(buffer);
zipEntry.Crc = crc.Value;
BackupZip.PutNextEntry(zipEntry);
BackupZip.Write(buffer, 0, buffer.Length);
(Note: I use #ZipLib)
The Full error:
System.UnauthorizedAccessException was caught
Message="Access to the path 'C:\\ATI' is denied."
Source="mscorlib"
StackTrace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at System.IO.File.OpenRead(String path)
at Chad.BackupIt.ZipBackup() in D:\Kode\BackupIt\BackupIt\BackupIt.cs:line 93
Message="Access to the path 'C:\\ATI' is denied."
Source="mscorlib"
StackTrace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at System.IO.File.OpenRead(String path)
at Chad.BackupIt.ZipBackup() in D:\Kode\BackupIt\BackupIt\BackupIt.cs:line 93

