Click here to Skip to main content
15,884,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

C#
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:

C#
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";//importXMLTB.Text = @"F:\year2\Data Cent Win Prog\Assignemnt 2\Assignment2\Assignment2\Books.xml";
            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.
Posted
Comments
Clifford Nelson 8-May-12 12:06pm    
Are you getting an error when you save the file? Have you stepped through the code so you know it is executing?
BBCokeley 8-May-12 12:22pm    
there was no error it was writing an empty xml file, because the dataset i was passing it was also empty.

ive solved this below.
thank you for your comment.

1 solution

Strange solution, but here we go.

what i did was pretty much use the code from my load into the data grid function, this was it loaded into a dataset ready to be written to the xml file at a location of my choice.

if you would like to see how it is done please post :)

regards
Matt.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900