Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET Relative Paths in Referenced Libraries
    primarykey
    data
    text
    <p>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).</p> <p>When I run the website, ASP.NET tries to find the xml file in the <em>source</em> 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.</p> <pre><code>// 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" ); </code></pre> <p>Here is the exception showing the path we are looking in is the same as Config.cs:</p> <pre><code> Exception Details: System.IO.FileNotFoundException: Could not find file 'C:\temp\Project.Core\validation_rules.xml'. </code></pre> <p>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.</p> <h2>UPDATE</h2> <p>Here is the relevant code for LoadRulesFromXml</p> <pre><code>public void LoadRulesFromXml( string in_xmlFileName, string in_type ) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load( in_xmlFileName ); ... </code></pre> <h2>UPDATE2</h2> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload