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 189087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:08:35+00:00 2026-05-11T16:08:35+00:00

I have an ASP.NET website in which I am loading some validation rules from

  • 0

I have an ASP.NET website in which I am loading some validation rules from an xml file. This xml file name, with no path info, is hard coded in a library. (I know that the hard coded name is not good, but let’s just go with it for this example).

When I run the website, ASP.NET tries to find the xml file in the source path, where the C# file in which name is hard coded is. This is completely mind boggling to me, as I can’t fathom how, at runtime, we are even considering a source path as a possibility for resolving an unqualified filename.

// the config class, in C:\temp\Project.Core\Config.cs
public static string ValidationRulesFile {
   get { return m_validationRulesFile; }
} private static string m_validationRulesFile = "validation_rules.xml";

// using the file name
m_validationRules.LoadRulesFromXml( Config.ValidationRulesFile, "Call" );

Here is the exception showing the path we are looking in is the same as Config.cs:

  Exception Details: System.IO.FileNotFoundException: 
Could not find file 'C:\temp\Project.Core\validation_rules.xml'.

Can anyone explain this to me? I already know how you are supposed to handle paths in general in ASP.NET so please don’t respond with solutions. I just really want to understand this, since it really surprised me, and It is going to bother me to no end.

UPDATE

Here is the relevant code for LoadRulesFromXml

public void LoadRulesFromXml( string in_xmlFileName, string in_type ) 
{       
    XmlDocument xmlDoc = new XmlDocument();
    xmlDoc.Load( in_xmlFileName );
... 

UPDATE2

It looks like the Cassini web server gets its current directory set by VS, and indeed it is set to the path of my library project. I’m not sure exactly how VS determines which project to use for the path, but this at least explains what is happening. Thanks Joe.

  • 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-11T16:08:35+00:00Added an answer on May 11, 2026 at 4:08 pm

    If you don’t supply a path, then file access will normally use the current working directory as the default. In ASP.NET this is probably your web application directory.

    It’s not usually a good idea to rely on the current working directory, so you can use Path.Combine to specify a different default directory, e.g. one relative to AppDomain.CurrentDomain.BaseDirectory, which is also the web application directory for an ASP.NET app.

    You should add the path explicitly to the name of the file you’re opening. You could also try tracing the current working directory.

    When running Cassini from Visual Studio, the current directory is inherited from whatever happens to be Visual Studio’s working directory: this seems to be your case.

    I.e.:

    public void LoadRulesFromXml( string in_xmlFileName, string in_type ) 
    {   
        // To see what's going on
        Debug.WriteLine("Current directory is " +
                  System.Environment.CurrentDirectory);    
    
        XmlDocument xmlDoc = new XmlDocument();    
    
        // Use an explicit path
        xmlDoc.Load( 
           System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
           in_xmlFileName) 
        );
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 92k
  • Answers 92k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer def round(s) s.to_f.round end round("5.344") # 5 round("-2.345") # -2… May 11, 2026 at 6:26 pm
  • Editorial Team
    Editorial Team added an answer I have finally managed to find the answer! There seems… May 11, 2026 at 6:26 pm
  • Editorial Team
    Editorial Team added an answer I would use the HBM2DDL to generate the database, then… May 11, 2026 at 6:26 pm

Related Questions

Good evening/morning/after/noon. I have an ASP.net 3.5 website and I am using vb.net in
Good evening/morning/after/noon. I have an ASP.net 3.5 website and I am using vb.net in
I have an ASP.NET website which uses the jQuery dialog to present the user
I have an asp.net website that uses forms authentication. There are a few things
I have an asp.net ajax website, it full of things happen on the same

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.