Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 976003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:40:39+00:00 2026-05-16T03:40:39+00:00

When my ASP.NET site uses documents (e.g. XML), I normally load the document as

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T03:40:39+00:00Added an answer on May 16, 2026 at 3:40 am

    If you know where it is relative to your web root, you can use Server.MapPath to 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:

    webRootPath = Server.MapPath("~")
    docPath = Path.GetFullPath(Path.Combine(rootPath, "../Documents/MyDocument.xml"))
    

    Sorry if I got the Syntax wrong, but the Path class 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.MapPath takes 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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

simple question... Given I have an ASP.NET site, which uses a [custom] RoleProvider, Is
I've got a ASP.NET site that's located on a local server (MY_SERVER). And one
I have an ASP.NET site that uses JQuery and ASP.NET UpdatePanel and ScriptManager. On
I have an ASP.NET MVC site that uses both Microsoft Ajax [ Ajax.BeginForm() ]
I'm building an ASP.NET MVC site that uses LINQ to SQL. In my search
I'm building an ASP.NET MVC site that uses LINQ to SQL to connect to
I'm building an ASP.NET MVC 2 site that uses LINQ to SQL. In one
I'm working on IIS6, ASP.NET, VS2008. The web site uses a custom error handler
I have an ASP.NET MVC site, that uses a CommandService. This command service is
Background I have an ASP.NET site, hosted internally on our company's intranet server. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.