i modified your code please see this
string companyID = this.Label1.Text;
string imgName = FileUpload1.FileName;
string imgPath = "~/Uploads/" + imgName;
int imgSize = FileUpload1.PostedFile.ContentLength;
string ext = System.IO.Path.GetExtension(this.FileUpload1.PostedFile.FileName);
if (FileUpload1.PostedFile != null && FileUpload1.PostedFile.FileName != "")
{
if (FileUpload1.PostedFile.ContentLength > 1000000)
{
Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Alert", "alert('File is too big.')", true);
}
if (ext.ToUpper().Trim() != ".JPG" && ext.ToUpper() != ".PNG" && ext.ToUpper() != ".GIF" && ext.ToUpper() != ".JPEG")
{
Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Alert", "alert('Please choose only .jpg, .png and .gif image types!')", true);
}
else
{
FileUpload1.SaveAs(Server.MapPath(imgPath));
Image1.ImageUrl = imgPath;
Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Alert", "alert('Image saved!')", true);
byte[] theImage = new byte[FileUpload1.PostedFile.ContentLength];
HttpPostedFile Image = FileUpload1.PostedFile;
Image.InputStream.Read(theImage, 0, (int)FileUpload1.PostedFile.ContentLength);
int length = theImage.Length;
string fileName = FileUpload1.FileName.ToString();
string type = FileUpload1.PostedFile.ContentType;
int size = FileUpload1.PostedFile.ContentLength;
if (FileUpload1.PostedFile != null && FileUpload1.PostedFile.FileName != "")
{
WP_advBLL canwork = new WP_advBLL();
canwork.ExecuteInsert(theImage, type, size, fileName, length, companyID);
Response.Write("File has been uploaded successfully!");
Session["imageID"] = imgName;
}
}
}