Reputation: 127
I am using microsoft visual studio and had created a solution file with 2 projects inside. Inside one of the aspx file in project A, I had a file upload control.
When the "upload" button is onclick, it would save the image I uploaded into a folder in Project A as well as a folder in Project B. I am only able to save the image into Project A folder using the below code.
FileUpload1.SaveAs(Server.MapPath("~/Images/" + filename));
But I am unable to save the images into Project B folder. with the code below, it had generate this error: ImagesFile is a folder inside Project B
FileUpload1.SaveAs(Server.MapPath("~/ImagesFile/" + filename));
Could not find a part of the path 'C:\Users\Desktop\DSC000015.JPG'.
Is there anyway that I had access the file path of another project???
Upvotes: 1
Views: 2251
Reputation: 6524
The problem here is Server.MapPath always gives you a path to inside your web directory. It will never be able to map a path outside your application.
You have two ways to accomplish this task.
1.Save a path in web.config file which should be an absolute path i.e. "c:\users\desktop\" and append the image name to this path.
or
2.You will have to create a page in project 2 which should accept images in post and save in a particular folder. So whenever an image is uploaded in project 1, it in turn, posts it to project 2 which ultimately saves it to a folder mapped inside its directory.
Upvotes: 1