Hi,
Use this logic..
1. After update the records in database, check whether the upload folder is exist or not..
2. If not exist create a folder..
3. and then save the file
Use the below code.
protected void btnUpdate2_Click(object sender, EventArgs e)
{
string EmpID = (string)Request.QueryString["empid"];
try
{
string constr = ConfigurationManager.ConnectionStrings["ConStr"].ToString();
SqlConnection con = new SqlConnection(constr);
con.Open();
SqlCommand cmd = new SqlCommand("[Usp_UpdateProfile]", con);
cmd.Parameters.AddWithValue("@name", txtEmpName.Text);
cmd.Parameters.AddWithValue("@mysiteurl", txtMySiteURL.Text);
cmd.Parameters.AddWithValue("@ro", txtRO.Text);
cmd.Parameters.AddWithValue("@email", txtEMail.Text);
cmd.Parameters.AddWithValue("@resume", FileUpload1.FileName.ToString());
cmd.Parameters.AddWithValue("@empid", EmpID);
cmd.CommandType = CommandType.StoredProcedure;
cmd.ExecuteNonQuery();
con.Close();
if (FileUpload1.FileName != "")
{
if(System.IO.Directory.Exists(MapPath(".") + "\\Uploads") == false) { System.IO.Directory.CreateDirectory(MapPath(".") + "\\Uploads"); }
string strDestination = AppDomain.CurrentDomain.BaseDirectory + "Uploads\\" + System.IO.Path.GetFileName(FileUpload1.FileName); FileUpload1.PostedFile.SaveAs(strDestination);
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
|