I have below code with var flag1 in my add button which is used to check whether the file that is choosed in file uploader already exists or not before inserting into database
This code is working fine when i have single file but now i am taking multiple files in fileuploader i need to check whether all the file exists or not if exists i should skip those files and insert remaining files but
my CheckFileExist method is returning back for the first file only since i am using return false in CheckFileExist method in else condition.
There is no problem when i am doing for single file but while doing for multiple files its not working
protected void btnadd_Click(object sender, EventArgs e)
{
var flag1 = CheckFileExist(Session["sid"].ToString(), value + ".mp3", Session["type"].ToString(), Session["phname"].ToString(), Docname, TFiName, DrfName, filuploadmp3.HasFile, Type, DrftFName);
if (!flag1)
return;
}
private bool CheckFileExist(string SName, string FName, string Stype, string PName, string DName, string TFName, string DraftFileName, bool HasFile, string Type, string DraftName)
{
var flag1 = false;
string qry = string.Empty;
if (Type == "Add")
{
if (Stype == "Draft")
{
qry = "select ID,SubjectID,auditoName from Subjectstu where (SubjectID='" + SName + "' and auditoName='" + FName + "' and AuditoType='" + Stype + "' and Physician='" + PName + "') or (BDocName='" + DName + "') or( DDocName='" + DrftFName + "') ";
}
else
{
qry = "select ID,SubjectID,auditoName from Subjectstu where (SubjectID='" + SName + "' and auditoName='" + FName + "' and AuditoType='" + Stype + "' and Physician='" + PName + "') or BDocName='" + DName + "' ";
}
}
else
{
if (Stype == "Draft")
{
qry = "select ID,SubjectID,auditoName from Subjectstu where (BDocName = '" + DocName + "' and ID <> " + Session["ID"] + ") or (DraftDocumentName = '" + DName + "' and ID <> " + Session["ID"] + ") or (SubjectID='" + SName + "' and auditoName='" + FName + "' and AuditoType='" + Stype + "' and Physician='" + PName + "' and ID <> " + Session["ID"] + ")";
}
else
{
qry = "select ID,SubjectID,auditoName from Subjectstu where (BDocName = '" + DocName + "' and ID <> " + Session["ID"] + ") or (SubjectID='" + SubjName + "' and auditoName='" + FName + "' and AuditoType='" + Stype + "' and Physician='" + PName + "' and ID <> " + Session["ID"] + ")";
}
}
SqlCommand cmd = new SqlCommand(qry, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
if (HasFile == false)
{
lblerrmsg.Visible = true;
lblerrmsg.Text = "File Already Exist ...!";
return false;
}
else
{
lblerrmsg.Visible = true;
lblfname.Text = "";
lbldocname.Text = "";
pnl1.Visible = true;
btnupdate.Enabled = false;
lblerrmsg.Visible = true;
btnadd.Enabled = true;
string Subjects = "select ID, Subject from Subjectsstu where Module = '" + null + "'";
BindDropDownList(ddlsubjname, Subjects, "Subject", "ID", "--Select--");
lblerrmsg.Text = "File Already Exist ...!";
if (IsPostBack)
{
BindGrid();
}
Clear();
return false;
}
}
flag1 = true;
return flag1;
}