We are storing file(s) in the database using byte[] in SQL. I am trying to do a simple check to find out if the file exists before proceeding with my method.
My problem is that even attempting to check the files existence results in an exceception.
Here are the 2 attempts ive tried:
var file = db.Attachments.Where(x => x.ResultsID == testResult).FirstOrDefault();
if(file.Data.Length == 0)
{
//do stuff
}
And this
var file = db.Attachments.Where(x => x.ResultsID == testResult).FirstOrDefault();
if(file.Data == null)
{
//do stuff
}
Both result in null reference exceptions due to Data, a byte[] being null, not empty, due to there being no file there.
How can I check whether a db file of type byte[] exists?