Image Upload:
In this case, use a FileUpload Control(Id:->FileUpload1), an ImageButton(ImageButton1) or you can use the Image, a Button Control(Id:->Updatebttn) to upload the Image, Button Control(Id:->Addbttn) to add the Image in database, an image(which we want to upload) , add a new folder (Image) in the WebForm.
Steps:
1. Create a table in the database(abc):
2. Coding for connectionstring in web.config
2 | < add name = "conn" connectionString = "Data Source=MAHAK\SQLEXPRESS;Initial Catalog=abc;Integrated Security=True;" /> |
3. In My WebForm(Page1.aspx.cs):
providerName:
3 | using System.Data.SqlClient; |
connectionstring:
1 | SqlConnection conn1 = new SqlConnection(ConfigurationManager.ConnectionStrings[ "conn" ].ConnectionString); |
4.Uploadbttn Coding:
01 | if (FileUpload1.HasFile) |
04 | string fileName = FileUpload1.FileName.ToString(); |
05 | string uploadFolderPath = "~/Image/" ; |
06 | string filePath = HttpContext.Current.Server.MapPath(uploadFolderPath); |
08 | FileUpload1.SaveAs(filePath + "\\" + fileName); |
10 | ImageButton1.ImageUrl = |
12 | "~/Image/" + "/" + FileUpload1.FileName.ToString(); |
5.Addbttn Coding:
3 | SqlCommand cmd3 = new SqlCommand( "insert into Image1(image1) values('" + ImageButton1.ImageUrl + "')" , conn1); |
Create a table in the database(abc):
use FileUpload Control and a Button(Id:->Uploadbttn)
in this case add a folder(Audio) in WebForm
0 comments:
Post a Comment