1
PhotoUpload.SaveAs(Server.MapPath("C:\\Users\\Renu\\Documents\\Visual Studio 2010\\WebSites\\matrimony\\App_Data\\images"+filename));

Here, PhotoUpload is name of a FileUpload component, filename is a simple string object. the content of PhotoUpload should be saved into the folder named "images" under App_Data folder. but after executing, I get the following error:

C:/Users/Renu/Documents/Visual Studio 2010/WebSites/matrimony/App_Data/images

Is a physical path, but a virtual path was expected. I don't know how to solve this error.

Ashley Medway
  • 7,151
  • 7
  • 49
  • 71
user3162403
  • 13
  • 1
  • 1
  • 4

2 Answers2

1

A guide on ASP.NET MapPath.

PhotoUpload.SaveAs(Server.MapPath(@"~\App_Data\images\"+filename));

Where filename = "myFile.png"

Using @ to provide a literal string.

Community
  • 1
  • 1
Ashley Medway
  • 7,151
  • 7
  • 49
  • 71
0

write this way:

* ~ get the path for the website i assume that your website path is C:\Users\Renu\Documents\Visual Studio 2010

PhotoUpload.SaveAs(Server.MapPath("~\\App_Data\\images"+filename)));
pankeel
  • 1,138
  • 1
  • 10
  • 22