/// /// Read a binary file /// /// Absolute Path of file to read from /// byte[] myFile = myFileObj.ReadBinaryFile(@"C:\log.txt"); /// Byte contents of the file public byte[] ReadBinaryFile(string filePath) { byte[] file = null; FileStream fs = null; BufferedStream bufs = null; BinaryReader bs = null; try { fs = new FileStream(filePath,FileMode.Open, FileAccess.Read); bufs = new BufferedStream(fs); bs = new BinaryReader(bufs); long lFile = bs.BaseStream.Length; if (lFile>Int32.MaxValue) // if file > 2GB { throw new Exception("File too long"); } file = bs.ReadBytes((int)lFile); this.errMsg=""; } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Source); System.Diagnostics.Debug.WriteLine(e.Message); System.Diagnostics.Debug.WriteLine(e.StackTrace); } finally { if (bs!= null) bs.Close(); if (bufs!=null) bufs.Close(); if (fs!=null) fs.Close(); } return file; }