1 .first create the folder to store the documents
here i created folder with name "documents"
2 after that create table in database like this
and in code behind
string FileName = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
//Save images into Images folder
FileUpload1.SaveAs(Server.MapPath("documents/" + FileName));
//Getting dbconnection from web.config connectionstring
//Open the database connection
con.Open();
//Query to insert images path and name into database
SqlCommand cmd = new SqlCommand("Insert into testing(ImageName,ImagePath) values(@ImageName,@ImagePath)", con);
//Passing parameters to query
cmd.Parameters.AddWithValue("@ImageName", FileName);
cmd.Parameters.AddWithValue("@ImagePath", "documents/" + FileName);
cmd.ExecuteNonQuery();
//Close dbconnection
con.Close();
here i created folder with name "documents"
and in code behind
string FileName = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
//Save images into Images folder
FileUpload1.SaveAs(Server.MapPath("documents/" + FileName));
//Getting dbconnection from web.config connectionstring
//Open the database connection
con.Open();
//Query to insert images path and name into database
SqlCommand cmd = new SqlCommand("Insert into testing(ImageName,ImagePath) values(@ImageName,@ImagePath)", con);
//Passing parameters to query
cmd.Parameters.AddWithValue("@ImageName", FileName);
cmd.Parameters.AddWithValue("@ImagePath", "documents/" + FileName);
cmd.ExecuteNonQuery();
//Close dbconnection
con.Close();
No comments:
Post a Comment