dsb dsb - 1 month ago 18
ASP.NET (C#) Question

Server.MapPath does not find the path on Azure

I have deployed my project to Azure. In my project I have "App_Data\Images" folder.

Now I'm trying to do the following:

String filename = GLOBAL_IMAGES_VALS.GET_FILE_PREFIX(imageType) + "-" + User.Identity.GetUserId<int>().ToString() + Path.GetExtension(image.FileName);

String origPath = Server.MapPath("~\\App_Data")+"\\Images\\" + filename;


But then upon trying:

image.SaveAs(origPath);


I get this error message:


Could not find a part of the path
'D:\home\site\wwwroot\App_Data\Images\logo-10003065.jpg'.


How can I save my file to "App_Data\Images\"?

dsb dsb
Answer

The actual problem was that the sub-folder 'Images' did not exist. I can't remember why the publish process did not create this sub-folder, however I added it manually and then everything worked fine.

Comments