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

  • Home
  • SEARCH
  • 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 523377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:27:21+00:00 2026-05-13T08:27:21+00:00

This is probably something mind-numbingly obvious, but I’m new to c# so be gentle…

  • 0

This is probably something mind-numbingly obvious, but I’m new to c# so be gentle…

I have an application which (in theory) parses a text file into an array. Despite the text file being a peer of the aspx file I can’t get the relative path right. Don’t know if it makes any difference (I’d assume not) but I’m using code-behind.

My folder structure looks like this:

  • default.aspx
  • default.aspx.cs
  • default.aspx.designer.cs
  • album.cs
  • albums.txt
  • web.config

And this is the code I’m using:

 protected void Page_Load(object sender, EventArgs e)
    {

         string[] allLines = File.ReadAllLines(@"Albums.txt");
         Album[] Albums = new Album[allLines.Length];
         for (int i = 0; i < allLines.Length; i++)
         {
           string[] lineSplit = allLines[i].Split(',');
           Albums[i] = new Album();
           Albums[i].ID = Convert.ToInt32(lineSplit[0]);
           Albums[i].title = lineSplit[1];
           Albums[i].keyName = lineSplit[2];
       }
   }

However, when I build it I get an error saying albums.txt can not be found, and it fails.

Any pointers would be greatly appreciated.

Ben

  • 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-13T08:27:21+00:00Added an answer on May 13, 2026 at 8:27 am

    Server.MapPath specifies the relative or virtual path to map to a physical directory.

    * Server.MapPath(".") returns the current physical directory of the file (e.g. aspx) being executed
    * Server.MapPath("..") returns the parent directory
    * Server.MapPath("~") returns the physical path to the root of the application
    * Server.MapPath("/") returns the physical path to the root of the domain name (is not necessarily the same as the root of the application)
    

    An example:

    Let’s say you pointed a web site application (http://www.example.com/) to

    C:\Inetpub\wwwroot

    and installed your shop application (sub web as virtual directory in IIS, marked as application) in

    D:\WebApps\shop

    If, for example, you call Server.MapPath in following request:

    http://www.example.com/shop/product/GetProduct.aspx?id=2342

    then,

    * Server.MapPath(".") returns D:\WebApps\shop\products
    * Server.MapPath("..") returns D:\WebApps\shop
    * Server.MapPath("~") returns D:\WebApps\shop
    * Server.MapPath("/") returns C:\Inetpub\wwwroot
    * Server.MapPath("/shop") returns D:\WebApps\shop
    

    If Path starts with either a forward (/) or backward slash (), the MapPath method returns a path as if Path were a full, virtual path.

    If Path doesn’t start with a slash, the MapPath method returns a path relative to the directory of the request being processed.

    Note: in C#, @ is the verbatim literal string operator meaning that the string should be used “as is” and not be processed for escape sequences.

    Server.MapPath("."), Server.MapPath("~"), Server.MapPath(@"\"), Server.MapPath("/"). What is the difference?

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

Sidebar

Related Questions

This is probably something simple but it's driving me nuts. I'm making some pagination
This is probably something easy to accomplish. I have some dates in my MySQL
This is probably something very simple but I'm not getting the results I'm expecting.
First of all I'm sorry if you feel this question has been raised before,
I have a perl script that I need to tweak. The script runs and
I stumbled upon an interesting error that I've never seen before, and can't explain
I recently had a discussion with a co-worker on whether we should allow null
I'm working on a public release if a model using Fortran 9x and I'd
Once again I need some help. I'm working with a table that contains 3
I'm just getting started with MySql and need to run simple queries on 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.