1

When i start to attach the same file to AdRotator object, it didn't work :

AdRotator1.AdvertisementFile = Server.MapPath("~/Data/Ads.xml");

Then i used, and it worked:

AdRotator1.AdvertisementFile = "~/Data/Ads.xml";

Can anyone tell me when to use Server.MapPath?

Ricardo Serra
  • 354
  • 2
  • 11
  • 1
    Possible duplicate of [Server.MapPath("."), Server.MapPath("~"), Server.MapPath(@"\"), Server.MapPath("/"). What is the difference?](http://stackoverflow.com/questions/275781/server-mappath-server-mappath-server-mappath-server-mappath) – Koby Douek Mar 20 '17 at 15:24

2 Answers2

1

The MapPath method maps the specified relative or virtual path to the corresponding physical directory on the server

Przemysław Kleszcz
  • 506
  • 1
  • 7
  • 13
1

From Microsoft: The MapPath method maps the specified relative or virtual path to the corresponding physical directory on the server.

So when you call Server.MapPath("~/Data/Ads.xml") it returns the complete path, including the directory on the server. But in your case, you probably just need the relative path, so you don´t need to call Server.MapPath.

  • so , how can i know if i will use the relative path or virtual path ? – Ahmed Abd-elbaqi Mar 20 '17 at 15:28
  • 1
    Normally, you use relative paths when your intention is to refer to na internal resource, like an image, file or page, and you use absolute paths when linking to another website. [Here is a good link to better understand the difference between them](http://www.coffeecup.com/help/articles/absolute-vs-relative-pathslinks/). –  Mar 20 '17 at 15:32