hoow to inset into database default image in byte formate when not selecting image from fileupload.

protected void subbtn_Click(object sender, EventArgs e)
{
if (fp.FileContent == null)
{
Byte[] imgByte = new Byte["image/1.jpg".Length];
}
else
{


FileUpload img = (FileUpload)fp;


Byte[] imgByte = null;
if (img.HasFile && img.PostedFile != null)
{
//To create a PostedFile
HttpPostedFile File = fp.PostedFile;


//Create byte Array with file len
imgByte = new Byte[File.ContentLength];
//force the control to load data in array
File.InputStream.Read(imgByte, 0, File.ContentLength);


}
}
int k = bs.usrdtinsert(txtfname.Text, txtlname.Text, txtemail.Text, txtpwd.Text, txtdb.Text, txtmob.Text, countrylist.Text, statelist.Text, citylist.Text, RadioButtonList1.Text, imgByte, desiglist.Text, txtkey.Text);

hoow to inset into database default image in byte formate when not selecting image from fileupload.

 protected void subbtn_Click(object sender, EventArgs e)
    {
        if (fp.FileContent == null)
        {
            Byte[] imgByte = new Byte["image/1.jpg".Length];
        }
        else
        {

            FileUpload img = (FileUpload)fp;

            Byte[] imgByte = null;
            if (img.HasFile && img.PostedFile != null)
            {
                //To create a PostedFile
                HttpPostedFile File = fp.PostedFile;

                //Create byte Array with file len
                imgByte = new Byte[File.ContentLength];
                //force the control to load data in array
                File.InputStream.Read(imgByte, 0, File.ContentLength);

            }
        }
        int k = bs.usrdtinsert(txtfname.Text, txtlname.Text, txtemail.Text, txtpwd.Text, txtdb.Text, txtmob.Text, countrylist.Text, statelist.Text, citylist.Text, RadioButtonList1.Text, imgByte, desiglist.Text, txtkey.Text);

end quote.

I say, declare Byte[] imageByte = null before starting of If condition in your subbtn_Click event. then write below some line of code in first if part :

Byte[] imageByte = null
if (fp.FileContent == null)
{
FileInfo fInfo = new FileInfo("image/1.jpg");
imageByte = new byte[fInfo.Length];
FileStream fStream = fInfo.OpenRead();
fStream.Read(imageByte , 0, imageByte .Length);
fStream.Close();
}

here your else part remain as it is just remove Byte[] imageByte = null as we have declared it starting of If condition.

I hope it will help you.

Please mark it as solved, if your problem get solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.