Reputation: 13
I have a tracking program that saves a hidden XML file during a save or auto save in case the user accidentally closes the program and needs to load it back up. It is imported into a dataset and data table.
Here's the code for the WriteXML and ReadXML:
WriteXML:
private void SaveloadFile()
{
string Timefor = Properties.Settings.Default.DateFormat;
System.Data.DataTable dt = (System.Data.DataTable)dataGridView1.DataSource;
string Filelocation = Properties.Settings.Default.SaveLocation.ToString() + "_" + System.DateTime.Today.ToString(Timefor) + ".xml";
try
{
dt.WriteXml(Filelocation, XmlWriteMode.WriteSchema);
FileInfo xm = new FileInfo(Filelocation);
xm.Attributes = FileAttributes.Hidden;
}
catch(System.Exception err)
{
MessageBox.Show("Ah poop, Something went wrong\n" + err, "Oh poop", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
ReadXML:
public void ReadXML(string Filepath)
{
try
{
dt.ReadXml(Filepath);
ds.Tables.Add(dt);
dataGridView1.DataSource = ds.Tables[0];
}
catch (System.Exception err)
{
MessageBox.Show("Ah poop, Something went wrong\n" + err, "Oh poop", MessageBoxButtons.OK, MessageBoxIcon.Information);
CreateDataBase();
}
}
And it seems to work. Although after opening the application and trying to save current work, I get this.
This only happens when I load the program and try to save.
I've looked into the code and I think I boiled it down to the readxml not letting go after reading. Though I have some suspicions that the writexml isn't working right ether.
I've looked around and I can't seem to find a solution to this bug.
If anyone can tell me what's wrong with the code that'll be great!
Upvotes: 0
Views: 159