I want to Upload a Image with FileUpload and store it in database and the code for it is this :
string filePath = FileUpload1.PostedFile.FileName;
string filename = Path.GetFileName(filePath);
string ext = Path.GetExtension(filename);
string contenttype = String.Empty;
//Set the contenttype based on File Extension
if (contenttype != String.Empty)
{
Stream fs = FileUpload1.PostedFile.InputStream;
BinaryReader br = new BinaryReader(fs);
Byte[] bytes = br.ReadBytes((Int32)fs.Length);
//insert the file into database
f.photo = Convert.ToString(FileUpload1.FileBytes);
Label1.ForeColor = System.Drawing.Color.Green;
Label1.Text = "File Uploaded Successfully";
}
but I get this error:
error :Object reference not set to an instance of an object.`
in
string filename = Path.GetFileName(filePath);
What is causing this?
thanks