2

I am using code that will get the root path

return HttpContext.Current.Server.MapPath(@"\Schedules\"); 

This works great when my site is installed as a fully fledged web app. but when its installed as a virtual directory it breaks, because it is looking for files in root folder, and not in \virtualdirectorypath folder.

Is there a way I can change the code to look for files from the virtual directory root, but also so it won't break if the app is installed as a fully fledged website?

3 Answers 3

4

Try this:

return HttpContext.Current.Server.MapPath(@"~/Schedule/"); 
Sign up to request clarification or add additional context in comments.

Comments

1

Use ~ root operator.

Server.MapPath("~"); // path of root of web application. 

Comments

0

See my answer on Base URL in ASP.net Master Pages with virtual Directories

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.