hi
I have 1 fileupload control that I can upload file from it below is code :
int count = 0;
if (this.fuppdf.HasFile && !string.IsNullOrEmpty(this.txtarticle.Text))
{
string[] validext = { ".pdf" };
//string ext = System.IO.Path.GetExtension(fuppdf.PostedFile.FileName);
string ext = Path.GetExtension(fuppdf.PostedFile.FileName);
string[] files = Directory.GetFiles(Server.MapPath("~/image/House/article/pdf/"));
if (Array.IndexOf(validext, ext.ToLower()) < 0)
{
lblpdf.Text = "* upload pdf files.";
return;
}
if (File.Exists(Server.MapPath("~/image/House/article/pdf/") + this.txtarticle.Text + ext))
{
foreach (string s in files)
{
string filename = string.Empty;
filename = Path.GetFileName(s).Substring(0, Path.GetFileName(s).LastIndexOf("."));
if (filename.Contains("("))
{
filename = filename.Substring(0, filename.LastIndexOf("("));
}
if (filename == this.txtarticle.Text.Trim())
{
count++;
}
} this.fuppdf.PostedFile.SaveAs(Server.MapPath("~/image/House/article/pdf/") + this.txtarticle.Text + "(" + count.ToString() + ")" + ext);
}
else
{
this.fuppdf.PostedFile.SaveAs(Server.MapPath("~/image/House/article/pdf/") + this.txtarticle.Text + ext);
}
and with below code I want save filename (uploaded filename) in database
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"]));
but it make error in this line
_cmd.Parameters.AddWithValue("@pdf", filename);
error===>("The name 'filename' doesn't exist in the current context")
I know that I define filename in
foreach (string s in files)
but I don't know how I can save it name in database
Best Regards
Neda