Reputation: 582
I was trying to upload some images in my website using input type=file in my asp.net mvc project.while storing the image I used the following code and it is saving the image successfully.
var path2 = Path.Combine(Server.MapPath("~/Images"), filename.jpg);
artwork.SaveAs(path2);
After that I need to save the whole link ( http://example.com/Images/filename.jpg) into my table column. for that i tried this
tablename.imagelink = path2 ;
then in table column I am getting like D:\xxxxx\yyyy\example\Images\filename.jpg then i tried to save the whole link directly tablename.imagelink = Path.Combine(Server.MapPath("http://example.com/Images/"), filename.jpg); at that time I am getting an error: "is not a valid virtual path error" How to solve this. ?
Upvotes: 0
Views: 47
Reputation: 2797
Server.MapPath
requires the virtual path of the web server, and you get the error because you're passing the full path like this:
Server.MapPath("http://example.com/Images/")
You need to keep using this:
Server.MapPath("~/Images")
Upvotes: 1