Hi
the below code of button i am facing a problem with it, as it suppose to check if all files has file and then check all uploadfile extension with .jpg or .png if yes then complete the rest of the code
var files = new[] { LogoFileExtention, BizImg1FileExtention, BizImg2FileExtention, BizImg3FileExtention, PersImgFileExtention };
var extensions = new[] { ".jpg", ".png"};
if ((files.Intersect(extensions).Count()) > 0)
{
and if not then move to below code, but what is happening is if the extension is .doc or .pdf it complete as normally without stop on the below part of the code
else
{
imagesformtLbl.Text = "Images should be in .JPG or .PNG format only";
}
protected void btnSave_Click(object sender, EventArgs e)
{
string LogoFileExtention = System.IO.Path.GetExtension(logoFileUpload.FileName);
string BizImg1FileExtention = System.IO.Path.GetExtension(FileUploadimage1.FileName);
string BizImg2FileExtention = System.IO.Path.GetExtension(FileUploadImage2.FileName);
string BizImg3FileExtention = System.IO.Path.GetExtension(FileUploadImage3.FileName);
string PersImgFileExtention = System.IO.Path.GetExtension(persimgFileUpload1.FileName);
if (citiesdrdolst.Items.Count == 0)
{
alertpanel.Visible = true;
StateReqLbl.Text = "Please select state where you live.";
}
else
{
HttpCookie cookie = Request.Cookies.Get("Location");
string Location = string.Empty;
SqlConnection cn = new SqlConnection(sc);
SqlCommand cmd = new SqlCommand();
Location = cookie.Value;
if (CheckBox1.Checked)
{
if (logoFileUpload.HasFile || FileUploadimage1.HasFile || FileUploadImage2.HasFile || FileUploadImage3.HasFile || persimgFileUpload1.HasFile)
{
var files = new[] { LogoFileExtention, BizImg1FileExtention, BizImg2FileExtention, BizImg3FileExtention, PersImgFileExtention };
var extensions = new[] { ".jpg", ".png" };
if ((files.Intersect(extensions).Count()) > 0)
{
string sqlstatment = @"INSERT INTO UserInfo (UID, FN, LN, Password, RePass, Email,Country, State,City, Post, Img, Logo,
RegDate,Address, UsrType,BizCateg,BizSubCateg, CompNme, Facebook, GooglePlus, Twitter, Website, image1, image2, image3) VALUES
(@UID,@FN,@LN,@Password,@RePass,@Email,@Country,@State,@City,@Post,@Img,@Logo,@RegDate,@Address,@UsrType,@BizCateg,@BizSubCateg,
@CompNme,@Facebook,@GooglePlus,@Twitter,@Website,@image1,@image2,@image3)";
cmd.Connection = cn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = sqlstatment;
cmd.Parameters.AddWithValue("@UID", UsrNme.Text);
cmd.Parameters.AddWithValue("@FN", fnbox.Text);
cmd.Parameters.AddWithValue("@LN", lnamebox.Text);
}
Response.Redirect("User panel.aspx");
}
else
{
imagesformtLbl.Text = "Images should be in .JPG or .PNG format only";
}
}
else
{
string sqlstatment = @"INSERT INTO UserInfo (UID, FN, LN, Password, RePass, Email,Country, State,City, Post, Img,
RegDate,Address, UsrType,BizCateg,BizSubCateg, CompNme, Facebook, GooglePlus, Twitter, Website) VALUES
(@UID,@FN,@LN,@Password,@RePass,@Email,@Country,@State,@City,@Post,@Img,@RegDate,@Address,@UsrType,@BizCateg,@BizSubCateg,
@CompNme,@Facebook,@GooglePlus,@Twitter,@Website)";
cmd.Connection = cn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = sqlstatment;
cmd.Parameters.AddWithValue("@UID", UsrNme.Text);
cmd.Parameters.AddWithValue("@FN", fnbox.Text);
cmd.Parameters.AddWithValue("@LN", lnamebox.Text);
SqlDataAdapter ad = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
ad.SelectCommand = cmd;
ad.Fill(ds);
Session["UsrNme"] = UsrNme.Text;
}
Response.Redirect("User panel.aspx");
}
}
else
{
Label1.Text = "please check the box to continue";
}
}
}