How to check file upload name if file already upload then new name assign
If file already upload then new name assign and save it.
Below my code
protected void Button1_Click(object sender, EventArgs e)
{
pnl11.Visible = true;
int playid = 1; HttpPostedFile hpf;
try
{
HttpFileCollection hfc = Request.Files;
for (int i = 0; i < hfc.Count; i++)
{
hpf = hfc[i];
if (hpf.ContentLength > 0)
{
FileInfo finfo = new FileInfo(hpf.ToString());
if (finfo.Extension != ".exe" || finfo.Extension !=".txt" || finfo.Extension !=".doc")
{
DataSet ODT;
string[] D;
D = hpf.FileName.Split('\\');
string fname = D[D.Length - 1];
hpf.SaveAs(Server.MapPath("~/Userimage/") + System.IO.Path.GetFileName(hpf.FileName));
PHT.addtitle(System.IO.Path.GetFileName(hpf.FileName), k, alid);
showtitle();
}
else
{
Label1.Visible = true;
Label1.Text = "Invalid File";
}
}
}
}
catch (Exception ex)
{
Label1.Visible = true;
Label1.Text = ex.Message;
}
}
k=upload date
alid=albumid
public void addtitle(string title, string date, int alid)
{
Sqlcon();
string qry = "insert into album_photo(image_url,date,al_id)values(@image_url,@date,@al_id)";
SqlCommand cmd = new SqlCommand(qry, con);
cmd.Parameters.Add("@image_url", SqlDbType.VarChar, 100).Value = title;
cmd.Parameters.Add("@date", SqlDbType.VarChar, 100).Value = date;
cmd.Parameters.Add("@al_id", SqlDbType.Int, 100).Value = alid;
if (con.State == ConnectionState.Closed)
{
con.Open();
}
cmd.ExecuteNonQuery();
con.Close();
}