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?
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

[1650 byte] By [Chadk] at [2007-12-16]
# 1
It seems that you are trying to open a directory as a file. This does not work.
C:\ATI is a directory isn't it ?
MikeDanes at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 2
Ye! It is. How shall i do then?
Chadk at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 3
I have't used #ZipLib but I think the ZipEntry for a directory should have a Size equal to 0 and no data after it (no Write after you append the ZipEntry). Also the directory name must have a trailing '/' (see ZipEntry IsDirectory property documentation). After you add the ZipEntry for a directory you can use Directory.GetFiles(path) to get a list of all files in the directory and add those files to the archive.
MikeDanes at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Base Class Library...

.NET Development

Site Classified