hi
I have one textbox=txttitle and one fileupload control=fuppdf
below is fileupload control code:
if(this.fuppdf.HasFile)
{
string path = Server.MapPath(".") + "\\../image/House/article/pdf\\";
string filename = System.IO.Path.GetFileName(fuppdf.PostedFile.FileName);
string[] validext = { ".pdf" };
string ext = System.IO.Path.GetExtension(fuppdf.PostedFile.FileName);
if (Array.IndexOf(validext, ext.ToLower()) < 0)
{
lblpdf.Text = "*please insert pdf file.";
return;
}
while (System.IO.File.Exists(path + "\\" + filename))
{
filename = "1" + filename;
}
SqlCommand _cmd = new SqlCommand("Fileuppdf", _cn);
_cmd.CommandType = CommandType.StoredProcedure;
string data = Session["behcode"].ToString();
_cn.Open();
_cmd.Parameters.AddWithValue("@pdf", filename);
_cmd.Parameters.AddWithValue("@Behcode", data);
_cmd.Parameters.AddWithValue("@id", Convert.ToInt32(ViewState["Id"]));
object o = _cmd.ExecuteScalar();
int ID = (o != null && o != DBNull.Value) ? Convert.ToInt32(o) : 0;
if (ID > 0)
{
ViewState["Id"] = ID.ToString();
if (fuppdf.HasFile)
{
try
{
if (fuppdf.PostedFile.ContentLength < 102400)
{ fuppdf.PostedFile.SaveAs(Server.MapPath("~/image/house/article/image") + System.IO.Path.DirectorySeparatorChar + fuppdf.PostedFile.FileName);
lblpdf.Text = "* upload has been successfully.";
}
}
catch (Exception ex)
{
lblpdf.Text = "Some problem occurred while uploading the file. Please try after some time.";
}
}
else
{
lblpdf.Text = "Please choose a file to upload.";
}
fuppdf.PostedFile.SaveAs(path + filename);
}
_cn.Close();
}
here I want when it want save name of pdf in database it save name with text that users enter in txttitle...
i.e:
users enter this text in txttitle: "City"
and the pdf file's name that they upload is jack.pdf
now I want in database it save with this name City.pdf
How I can do it?
Best Regards
Neda