ASP.NET relative paths in reference libraries

I have an ASP.NET site where I load some validation rules from an xml file. This xml file name, with no path information, is hard-coded in the library. (I know that a hard-coded name is not very good, but let's just talk about it in this example).

When I launch the website, ASP.NET tries to find the XML file in the source path, where is the C # file in which the name is hardcoded. This is completely embarrassing to me, because I cannot understand how, at run time, we even consider the source path as an opportunity to resolve an unqualified file name.

// 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's an exception showing the path we are looking for is the same as Config.cs:

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

- ? , ASP.NET, , , . , , .

UPDATE

LoadRulesFromXml

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

UPDATE2

, - Cassini , VS, . , VS , , , , , . .

+5
2

, . ASP.NET , , -.

, Path.Combine , . AppDomain.CurrentDomain.BaseDirectory, - ASP.NET.

, . .

Cassini Visual Studio , Visual Studio: .

:.

public void LoadRulesFromXml( string in_xmlFileName, string in_type ) 
{   
    // To see what 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) 
    );
...
+14

, LoadRulesFromXml() URL- , ... C:\temp\Project.Core \ , Server.MapPath("~")

LoadRulesFromXML ?

+2

All Articles