Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
How to save image name and image foldername into database giving physical path i.e www.xyz.com in asp.net mvc

But i am getting error like: The SaveAs method is configured to require a rooted path, and the path is not rooted.

If it is same server url then it works fine no issue,but i want to save image file to another server url and in that image folder.

What I have tried:

 [HttpPost]
        public ActionResult streetstyle(FormCollection frm, HttpPostedFileBase Upload)
        {
string ImageName = System.IO.Path.GetFileName(Upload.FileName);
            string physicalPath = "http://www.xyz.com/" + "/ImagesFolder/" + ImageName;
            Upload.SaveAs(physicalPath);

            db.Name = frm["Name"];
            db.Email = frm["Email"];
            db.Mobile = frm["Mobile"];

            db.Image = ImageName;
Posted
Updated 3-Feb-17 4:06am
v6

1 solution

Take a moment and think about what is happening. This code is running on your server. And SaveAs needs a physical path to a folder. So, instead do something like this:
C#
String physicalPath = Server.MapPath("~/ImagesFolder/"); // this will resolve to c:\inetpub\wwwroot\app1\imagesFolder or wherever the actual drive is.

Then just store ImageName into the db.
 
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