Loading xml Files

I come from a major ASP.NET background, so my way of thinking might be warped for client side development.

I'm very new to client side development for .NET. I'm working with serialization for this part and need help when reading / writing my files.

I have a folder called "Data" in my project. In that folder I have some xml files. One holds a list of "Packages". There are multiple "Package" elements that are serialized into this file (hope to be serialized). THere is an element that has a filename. This filename points to another XML file that contains all the information for that package.
***I do not want all information for all packages in 1 XML file, because that file will get longer than 600,000 lines in a matter of weeks.

I want to load that XML file up in my application, but All I can do is do:

string strPath = Application.StartupPath + "\\data\\test.xml";

That points me to the "Debug" or "Release" folders inside my bin. How can I tell it to grab the files I want it to grab Moreover, how do I tell it to put the "Data" folder and all contents in the Debug folder

I'm very new to this so help would be great :D

Thanks.




Answer this question

Loading xml Files

  • Shiby John

    Thanks for the help you guys,

    I guess this is what I'm trying to do:
    • Have an XML file that contains a list of packages
    • Have X amount of XML files that contain the details of each package.
    • Have all of these XML files in a directory called "Data"
      • When I compile / run the project I would like the "Data" folder to be created.
      • I though I did this.. I created the folder "Data" in my project, but it doesn't copy like ASP.NET does on a publish...
    That's the main part I'm trying to wrap my head around.

    The other part I'm having trouble with is how to load this data. I've created a class for the list of Packages that serializes and Deserializes the list to a Package.XML file - this works great.

    For the files that contain the Package Details, I'm not sure what the best method would be - Create an XML data set, or create custom classes to manage them. The relations I have within each package are:

    A Package has many sections. A Section has many items.

    I created a Package.xsd (DataSet) File/Item and created Tables.. but I don't know how to load an XML file with the DataSet Schema I created...

    Thanks for the help so far.


  • jewelfire

    To create the data folder, you could either create a post build step in your main project that creates this folder, or make it part of your application to create this folder if it doesn't exist (or on some other cue). To create a folder in code, use System.IO.Directory.CreateDirectory(). It seems you already know how to find the place to create it.

    To iterate over the files in the directory, use System.IO.Directory.GetFiles (or something like that).

    Then you can load up an XmlDocument or a DataSet, or whatever you prefer...

    WNC



  • R. Joseph Newton

    Well remember that wherever the application is going to be running from will be the application startup path - the debug folder (or release folder, depending on what build config you use) is where the IDE places the compiled output to.

     

    you can get all the files by using:

    string[] theFiles = System.IO.Directory.GetFiles(thePath, "*.xml");

    this will return a list of files of which the extension is of Xml.

     

    you can then copy the files using :

     

    foreach (string curFile in theFiles)

    {

       System.IO.File.Copy(curFile, outputPath, true); //true is to overwrite the existing file (if found)

    }

     

    however re reading your post, I believe this is not what you are quite looking for but rather move the files it mentions in the xml file

    If this is the case, perhaps you could load the xml in a dataset and navigate to the fields which have the filepaths/names mentioned, then do as above

     

    can you please clear this up



  • Loading xml Files