I'm working on a simple Insert, Fetch Web application. While inserting data I'm saving Images to the Folder "~/Photos/" and it's path in Database, But getting Error:
System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\Vipin\Documents\Visual Studio 2010\WebSites\NNSEnrollment\Photos\'.
The Folder is at its defined directory.
My Code is:
try
{
string filename = FileUpload1.FileName;
FileUpload1.PostedFile.SaveAs(Server.MapPath("~\\Photos\\" + filename.Trim()));
string path = "~\\Photos\\" + filename.Trim();
str = "insert into spouse_details (r_p_id,name,dob,contact,marriage_anniversary_date,image_path) values('" + Convert.ToInt16(lbl_r_p_id.Text) + "','" + txt_name_spouse.Text + "','" + Convert.ToDateTime(txt_sp_dob.Text) + "','" + txt_contact.Text + "','" + Convert.ToDateTime(txt_anniversary.Text) + "','" + path + "')";
dap = new OleDbDataAdapter(str, con);
dt = new DataTable();
dap.Fill(dt);
Response.Write("<script>alert('Submit');</script>");
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
Whereas the same code is working in Some other application earlier... Thank You in Advance