Question

my web application has an xml file here:

/files/xml/test.xml

I need to load a XDocument from within a class library project, how will I reference the xml? I don't want to pass any path parameters to this method.

I want to assume the location is fixed at /files/xml/test.xml.

How can I load a XDocument know this?

I don't seem to have access to server.mappath either.

Was it helpful?

Solution

You should never assume locations. Your function really should take a file path, then from your Web Context, you call server.mappath to produce the correct path to load.

If you want to fix something, load it in as a resource constant or a const variable.

public static class Globals
{
   public const string TestPath = "/files/xml/text.xml";
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top