Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello everyone, following the advises from a user here I'd store are the routes (ServerPath) from my pictures in my database, and I need to show them in my View, but I don't know how to do it, please, need your help, thanks...
Posted
Comments
[no name] 26-Sep-14 15:21pm    
Okay... what is a "picture route"? "show them"? What is "them"? What have you tried for yourself? Have you done any research at all?

1 solution

Hello, I did it by myself with the help of a friend, thanks all of you for the help, here is the code to save the path to the database:
C#
if (file != null && file.ContentLength > 0)
{
    // extract only the fielname
    var fileName = Path.GetFileName(file.FileName);
    // store the file inside ~/App_Data/uploads folder
    var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName); 
    image.Picture = fileName;
}

and to return the file and show it to the view this one:
C#
var path = ControllerContext.HttpContext.Server.MapPath("/");
if (System.IO.File.Exists(Path.Combine(path, file)))
{
   return File(Path.Combine(path, file), "image/jpeg");
}
return new HttpNotFoundResult();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900