views:

13

answers:

2
public class Hero
{

    XPathNavigator Navigator;
    XPathDocument HeroInformation;        

    public string GetHeroIcon(string Name)
    {            
        XDocument HeroInformation = XDocument.Load("InformationRepositories/HeroRepository/HeroInformation.xml");
        return HeroInformation.Descendants(Name).Single().Element("Icon").Value;
        //return doc.Descendants(name).Single().Element("Icon").Value;
    }

}

I get an error in the first line of my method. I don't understand why it's not working when the adress is clearly written correctly. I'm so confused with this.

Here's a picture of my solution explorer:

alt text

+1  A: 

When your application executes, it is executing from either the bin/Debug or bin/Release directory by default. The path you are trying to follow starts at those directories. You can use the full qualifying path or copy the file/folder structure into the Debug/Release directory. You can also set your application to compile to a different directory. Environment.CurrentDirectory will get you the directory you are executing from, and from there you can use Path.Combine to figure out the location you are looking for the file.

Yuriy Faktorovich
+2  A: 

your XDocument.Load() method has seeems to search for the requested file in the Bin/debug folder. you need do this to find the check the file at correct location.

XDocument HeroInformation = XDocument.Load("../../InformationRepositories/HeroRepository/HeroInformation.xml");
viky