I’m a bit lost about this I’m trying to upload images to my server and connect them to People Db table
I have created this 2 classes (as code first Project ) and I need to connect the images to the person details,
(to be clear )
the classes
public class Person
{
[Key]
public int PersonId { get; set; }
[Display(Name="Name")]
public string PersonName { get; set; }
//every person can have a few pictures
public List<Pictures> pictures { get; set; }
}
[Key]
public int ImageId { get; private set; }
public string ImageUrl { get; set; }
public int PersonId { get; set; }
//[Column(TypeName = "image")]
//public byte[] Image { get; set; }
the upload Action Results is :
[HttpGet]
public ActionResult uploadImages()
{
return View();
}
[HttpPost]
public ActionResult uploadImages(IEnumerable<HttpPostedFileBase> files)
{
foreach (var file in files)
{
if (file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath("/uploads/"), fileName);
file.SaveAs(path);
}
}
return RedirectToAction("Index");
}
DosNet
Member
115 Points
97 Posts
Upload images to server and getting the url in DB
Feb 21, 2012 12:15 PM|LINK
I’m a bit lost about this I’m trying to upload images to my server and connect them to People Db table
I have created this 2 classes (as code first Project ) and I need to connect the images to the person details,
(to be clear )
the classes
public class Person { [Key] public int PersonId { get; set; } [Display(Name="Name")] public string PersonName { get; set; } //every person can have a few pictures public List<Pictures> pictures { get; set; } } [Key] public int ImageId { get; private set; } public string ImageUrl { get; set; } public int PersonId { get; set; } //[Column(TypeName = "image")] //public byte[] Image { get; set; }the upload Action Results is :
[HttpGet] public ActionResult uploadImages() { return View(); } [HttpPost] public ActionResult uploadImages(IEnumerable<HttpPostedFileBase> files) { foreach (var file in files) { if (file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("/uploads/"), fileName); file.SaveAs(path); } } return RedirectToAction("Index"); }<form action="" method="post" enctype="multipart/form-data"> <label for="file1">Filename:</label> <input type="file" name="files" id="file1" /> <label for="file2">Filename:</label> <input type="file" name="files" id="file2" /> <input type="submit" /> </form>ignatandrei
All-Star
135150 Points
21680 Posts
Moderator
MVP
Re: Upload images to server and getting the url in DB
Feb 21, 2012 12:20 PM|LINK
after
DosNet
Member
115 Points
97 Posts
Re: Upload images to server and getting the url in DB
Feb 21, 2012 03:52 PM|LINK
Thanks,
yes this is what i'm tring , i need also to bount it to person id ,
and is not working out for my i dont understand why,
i need a littel more help
Thanks
ignatandrei
All-Star
135150 Points
21680 Posts
Moderator
MVP
Re: Upload images to server and getting the url in DB
Feb 21, 2012 07:54 PM|LINK
How are you trying? And what does it mean
? Error?Young Yang -...
All-Star
21343 Points
1818 Posts
Microsoft
Re: Upload images to server and getting the url in DB
Feb 28, 2012 02:18 AM|LINK
Hi
Look at this:
http://garfbradazweb.wordpress.com/2011/08/16/mvc-3-upload-sql-server-entity-framework/
and http://www.joshholmes.com/blog/2009/01/27/buildingasimplephotogalleryinaspnetmvcframework/
Hope this helpful
Regards
Young Yang
Feedback to us
Develop and promote your apps in Windows Store