0

Hi I'm currently learning to programm and i have run into a problem. I'm Saving user inputs into an xml file

private static void AddEntry(string GameName, string SavePath, string ExePath)
{
    if (!File.Exists(docname))
    {
        CreateXml();
    }
    XDocument doc = XDocument.Load(docname);
    XElement Game = doc.Element("Game");
    Game.Add(new XElement("GameName", GameName), new XElement("SavePath", SavePath), new XElement("ExePath", ExePath));
    doc.Save(docname);          
}

private static void CreateXml()
{
    XDocument SaveGameManager = new XDocument();
    SaveGameManager.Declaration = new XDeclaration("1.0", "utf-8", "yes");
    XElement Game = new XElement("Game");
    SaveGameManager.Add(Game);
    SaveGameManager.Save(docname);
}

now i need to be able to use these values, more specifically i need to use the GameName string in a dropdown menu. What is the simplest option for me to get this considering im not very experienced yet :)

edit: here is my xmlfile

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Game>
  <GameName>sfsdf</GameName>
  <SavePath>6835-256x256x8 (1).png</SavePath>
  <ExePath>arduino-1.8.2-windows.exe</ExePath>
  <GameName>fasdf</GameName>
  <SavePath>ClassDiagram simple.vsdx</SavePath>
  <ExePath>GameOfLife.exe</ExePath>
</Game>
Samuel
  • 65
  • 9
  • you should post your xml sample – BRAHIM Kamel Jun 09 '17 at 14:04
  • 3
    Possible duplicate of [Reading data from XML](https://stackoverflow.com/questions/7119806/reading-data-from-xml) – Bob Swager Jun 09 '17 at 14:04
  • Just so you're aware, there are concepts such as configuration and settings that are "built-in" to .NET. The sort of values you're storing look like they may be one or both of those things, so you might want to look into those also (unless this is, strictly, for you trying to learn about the Xml support in .NET) – Damien_The_Unbeliever Jun 09 '17 at 14:12
  • @Damien_The_Unbeliever what im doing is buidling a small application to backup my video game saves. i get the user to supply the path to the save and the videogames exe and also the games name. the user can then launch said game with my application and after closing the game its supposed to backup the save. – Samuel Jun 09 '17 at 14:19
  • Well, those do sound like *settings*, don't they? Here's an introduction to [Managing Application Settings](https://msdn.microsoft.com/en-us/library/a65txexh.aspx) – Damien_The_Unbeliever Jun 09 '17 at 14:25
  • You need to fix you xml. Your two Game should be separate elements with properties as children. You have the properties as siblings. – jdweng Jun 09 '17 at 14:34

0 Answers0