Hey all,
I'm attempting to read a binary file and I keep getting errors on 64-bit systems where it appears that the file is being open with write privileges and thus throws an error when placed in a secure folder (Program Files in 64 bit Windows). I can duplicate this error on my system (XP, 32 bit) by setting the folder containing the documents to be read to read-only.
Here's the code I'm using:
public static byte[] GetContentFromFile(string file)
{
try
{
FileStream stream = new FileStream(String.Format("{0}{1}", AppDomain.CurrentDomain.BaseDirectory, file), FileMode.Open, FileAccess.Read);
BinaryReader reader = new BinaryReader(stream);
byte[] content = new byte[stream.Length];
reader.Read(content, 0, content.Length);
reader.Close();
stream.Close();
return content;
}
catch
{
return new byte[0];
}
}
Any ideas?