Here is the story. I was doing a program, every time the program is closed all the data(File links) created by the user is lost, so whenever the user reopen the program, he does have to do all the work again.
So I decided to use an xml file to store the data, because a dbms would take too long to load and code to handle a plain text file would be hard to maintain.
The data is mainly composed of Links that stores two file paths, one for the origin and one for the destination, one boolean that represent the state of the link before the program is closed, and a few other less important things.
When the program loads the data should be read restoring the previous state of the application.
So I made a xml file like this:
...
<Directories>
<Directory id="0">
<FilePath>C:\Test1</FilePath>
<PathSeparator>\</PathSeparator>
</Directory>
...
And used a DataSet to get the data.
Directory getDirectory()
{
ds = new DataSet();
ds.ReadXml(xmlPath);
DataRow[] myRow = ds.Tables["Directory"].
Select("id ="+id.ToString());// "id = id"
string temp = myRow[0]["FilePath"].ToString();
Directory result = new Directory();
result.path = temp;
temp = myRow[0]["PathSeparator"].ToString();
result.pathSeparator = temp[0];
return result;
}
All that works just fine, but then I tried to add new "rows" to the xml:
public static int addDirectory(DataSet ds, char pathSeparator, string path)
{
DataRow myRow = ds.Tables["Directory"].NewRow();
myRow.ItemArray[0] = 8;
myRow.ItemArray[1] = path;
myRow.ItemArray[2] = pathSeparator.ToString();
myRow.ItemArray[3] = "lol";
ds.Tables["Directory"].Rows.Add(myRow);
ds.AcceptChanges();
ds.WriteXml(ApplicationDataManager.xmlPath);
return 8;
}
But all this writes is to a random place on the .xml
What am I doing wrong?
By the way if anyone have any suggestions about how I should store that data, I would be glad to hear(read).
Thanks in advance!
[Update] File Links are used to create a connection between two directories, so they can be synchronized.