Hi user93,
Refer the modified code.
C#
protected void btnadd_Click(object sender, EventArgs e)
{
for (int i = 0; i < Request.Files.Count; i++)
{
HttpPostedFile postedFile = Request.Files[i];
if (postedFile.ContentLength > 0)
{
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(postedFile.FileName);
string fileExtension = Path.GetExtension(postedFile.FileName);
if (fileExtension.ToLower() == ".mp3")
{
bool flag1 = CheckFileExist(Session["sid"].ToString(), fileNameWithoutExtension + ".mp3", Session["type"].ToString(), Session["phname"].ToString(), Docname, TFiName, DrfName, true, 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"] + ")";
}
}
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings[1].ConnectionString);
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)
{
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;
}