Um...
if (!string.IsNullOrEmpty(e.FullPath))
{
FileStream fs = new FileStream(e.FullPath, FileMode.Open, FileAccess.Read);
byte[] filebytes = new byte[fs.Length];
fs.Read(filebytes, 0, Convert.ToInt32(fs.Length));
string encodedData = Convert.ToBase64String(filebytes, Base64FormattingOptions.InsertLineBreaks);
Console.WriteLine(encodedData);
}
You don't close the file - so the next time you try to access it, it's still open! It won't get closed until the Garbage collector gets kicked in - next week, maybe - to clean up after you.
Try a
using
block:
if (!string.IsNullOrEmpty(e.FullPath))
{
using (FileStream fs = new FileStream(e.FullPath, FileMode.Open, FileAccess.Read))
{
byte[] filebytes = new byte[fs.Length];
fs.Read(filebytes, 0, Convert.ToInt32(fs.Length));
string encodedData = Convert.ToBase64String(filebytes, Base64FormattingOptions.InsertLineBreaks);
Console.WriteLine(encodedData);
}
}
And it will be Closed and Disposed when it goes out of scope.