hey guys, quick question thats been bugging me for a few hours.
i can retrieve an xml file from a directory that i specify really easy, i store this in a dataset to be passed to a datagrid etc..
now what im trying to do is save this exact file as it stands to a different directory, and i just cant figure it out, im trying to pass the current dataset to this object so that when i click the save button, it will save this xml file, say, on my desktop.
this is the code im using to save the file on desktop:
private void XMLpathBTN_Click(object sender, EventArgs e)
{
string myXMLFile = "F:\\year2\\Data Cent Win Prog\\Assignemnt 2\\Assignment2\\Assignment2\\Books.xml";
SaveFileDialog saveFile = new SaveFileDialog();
saveFile.DefaultExt = "xml";
saveFile.AddExtension = true;
saveFile.InitialDirectory = @"C:\Users\Matthew\Desktop\";
saveFile.OverwritePrompt = true;
saveFile.Title = "Save as XML File";
saveFile.FileName = "copiedXML";
saveFile.ValidateNames = true;
if (saveFile.ShowDialog() == DialogResult.OK)
{
ds.WriteXml(saveFile.FileName, XmlWriteMode.WriteSchema);
}
}
i know why its writing a blank dataset is because there is nothing in it, i want to pass the data from the load click event to this event so it has the same data ready from copying, ill post the load event aswell:
private void importXML_Click(object sender, EventArgs e)
{
OpenFileDialog loadXMLFile = new OpenFileDialog();
BindingSource bs = new BindingSource();
loadXMLFile.DefaultExt = "xml";
loadXMLFile.AddExtension = true;
loadXMLFile.InitialDirectory = @"F:\year2\Data Cent Win Prog\Assignemnt 2\Assignment2\Assignment2\Books.xml";
loadXMLFile.Title = "Loan an XML File";
loadXMLFile.FileName = "Books";
loadXMLFile.ValidateNames = true;
if (loadXMLFile.ShowDialog() == DialogResult.OK)
{
importedDS.ReadXml(loadXMLFile.FileName, XmlReadMode.InferTypedSchema);
bs.DataSource = importedDS.Tables[0];
DGTables.DataSource = bs;
}
}
just want to pass the above file to the save button file but i cant figure it out
Please help
Thanks
Matt.