I tried to open an xml file with open file dialog and want to removed some duplicate data from the file now my problem is selecting the file and saving that file (load, delete,save buttton on my winforms).can you please where am I going wrong.
我尝试用open file对话框打开一个xml文件,想从文件中删除一些重复的数据,现在我的问题是选择文件并保存该文件(在winforms上加载、删除、保存buttton)。你能告诉我哪里出错了吗?
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e) // open file dialog works fine
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "XML files(.xml)|*.xml|all Files(*.*)|*.*";
openFileDialog1.FilterIndex = 1;
openFileDialog1.Multiselect = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
{
}
}
}
private void button2_Click(object sender, EventArgs e)//Deleteing duplicate data
{
//var doc = XDocument.Load(@"C:\\Users\IT-Administrator\Desktop\21.xml");/ do i need to use this line.
doc.Root.Elements("Incident")
.GroupBy(s => (string)s.Element("Comment"))
.SelectMany(g => g.Skip(1))
.Remove();
//doc.Save(@"C:\Users\IT-Administrator\Desktop\2014-01-07_Middlesex.xml");
//doc.Save(@"C:\Users\IT-Administrator\Desktop\22.xml");
}
private void button3_Click(object sender, EventArgs e)//saving..
{
//doc.Save(@"C:\Users\IT-Administrator\Desktop\22.xml");
saveFileDialog1.ShowDialog();
}
1 个解决方案
#1
-1
To save your XML-File you have to:
要保存xml文件,您必须:
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "XML-File | *.xml";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
xDocument.Save(saveFileDialog.FileName);
}
#1
-1
To save your XML-File you have to:
要保存xml文件,您必须:
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "XML-File | *.xml";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
xDocument.Save(saveFileDialog.FileName);
}