传递一个xml文件,以便可以将其保存在其他地方 [英] passing an xml file so it can be saved elde where

查看:99
本文介绍了传递一个xml文件,以便可以将其保存在其他地方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,快速提问让我烦了几个小时.

我可以从我指定的目录中很容易地检索xml文件,我将其存储在数据集中以传递给datagrid等.

现在我想做的就是将这个确切的文件保存到另一个目录中,而我只是想不通,我试图将当前数据集传递给该对象,以便当我单击保存按钮时,它将保存此文件xml文件,例如,在我的桌面上.

这是即时消息用于将文件保存在桌面上的代码:

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);
            }
        }



我知道为什么写入空白数据集的原因是因为其中没有任何内容,我想将数据从load click事件传递到此事件,以便它具有从复制就准备好的相同数据,而且还会在load事件之后发布:



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";//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;
            }

        }



只想将上面的文件传递到保存按钮文件,但我无法弄清楚
请帮忙
谢谢
Matt.



just want to pass the above file to the save button file but i cant figure it out
Please help
Thanks
Matt.

推荐答案

奇怪的解决方案,但是我们开始吧.

我所做的几乎是使用我从加载到数据网格功能中的代码,这是将它加载到准备好在我选择的位置写入xml文件的数据集中.
如果您想知道它是如何完成的,请发表:)

问候
马特.
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.


这篇关于传递一个xml文件,以便可以将其保存在其他地方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆