I'm coding an Admin form. The user may or may not update PDF file(s); if he does I'm handling it in my form coded as follows:
string fileExt = System.IO.Path.GetExtension(regFormUpload.FileName);
if (regFormUpload.HasFile)
{
if (string.Equals(fileExt, ".pdf", StringComparison.OrdinalIgnoreCase))
{
Stream pdfFileStream = regFormUpload.PostedFile.InputStream;
fileData = new byte[regFormUpload.PostedFile.ContentLength];
pdfFileStream.Read(fileData, 0, regFormUpload.PostedFile.ContentLength);
// Call DALC method with uploaded file(s) params
}
else
{
regFormCustVal.IsValid = false;
}
}
else
{
// Call DALC method indicating "null" for non-uploaded files(s)???
}
Is there a way to pass a null to the DALC/Stored Procedure? It's being stored in SQL Server as a varbinary(max) type. Previously I used to code separate methods depending on whether or not someone uploaded a file and I know there has to be an easier way but the C# syntax is escaping me.
UPDATE - 05-24-2012
I still haven't got an answer to this. In my DALC, I currently have to call several DB update methods, depending on whether files (byte[]) has been uploaded or not. Is there anyway to get around this? I have two separate file upload controls and both are non-required fields. This means I have to code up to four separate DB update methods to account for the (2^2) possibilities!