When my ASP.NET site uses documents (e.g. XML), I normally load the document as follows:
Server.MapPath("~\Documents\MyDocument.xml")
However, I would like to move the Documents folder out of the website folder so that it is now a sibling of the website folder. This will make maintaining the documents considerably easier.
However, rewriting the document load code as follows:
Server.MapPath("../../Documents/MyDocument.xml")
results in a complaint from ASP.NET that it cannot ‘exit above the top directory’.
So can anyone suggest how I can relatively specify the location of a folder outside the website folder? I really don’t want to specify absolute paths for the obvious deployment reasons.
Thanks
David
If you know where it is relative to your web root, you can use
Server.MapPathto get the physical location of your web root, and then Path class‘s method to get your document path.In rough unchecked code something like:
Sorry if I got the Syntax wrong, but the
Pathclass should be what you are after to play with real FS paths rather than the web type paths.The reason your method failed is that
Server.MapPathtakes a location on your web server and the one you gave is not valid, since it is “above” the top of the root of the server hierarchy.