I am working on web pages(razor) asp.net using Webmatrix environment. I am trying to insert uploaded image path into database so i confuse which variable should be pass to query to make the path inserted into table. here is my code:
int numFiles = Request.Files.Count;
string fileName="";
if(IsPost)
{
for(int i =0; i < numFiles; i++) {
var uploadedFile = Request.Files[i];
if (uploadedFile != null)
{
fileName= Path.GetFileName(uploadedFile.FileName);
uploadedFile.SaveAs(Server.MapPath(Path.Combine("~/documents/", fileName)));
}
}
}
Here is my query to insert into database but i dont know what how o insert the path into database.
int numFiles = Request.Files.Count;
string fileName="";
if(IsPost)
{
for(int i =0; i < numFiles; i++) {
var uploadedFile = Request.Files[i];
if (uploadedFile != null)
{
fileName= Path.GetFileName(uploadedFile.FileName);
uploadedFile.SaveAs(Server.MapPath(Path.Combine("~/documents/", fileName)));
}
}
}
To store image in database you just need insert particular image location (in the form of string) on the server of your image into database table.
for example: to store "photo.jpg" in the database first upload it to your server, next get the path of image at your server, save the path in the database table(ex: INSERT INTO table_name VALUES (....,Path,...);)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.