8,757
社区成员
发帖
与我相关
我的任务
分享private void button1_Click(object sender, RoutedEventArgs e)
{
try
{
XElement imgBox = new XElement("imgBox", new XElement("img", new XElement("source", "asdsad"), new XElement("width", "150"), new XElement("height", 150)));
XDocument imgXml = new XDocument(new XDeclaration("1.0", "utf-8", "yes"), new XComment("这是一个XML文件"), imgBox);
using (IsolatedStorageFile userFile = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream("imgXml.xml", FileMode.Create, userFile))
{
imgXml.Save(fileStream);
fileStream.Close();
MessageBox.Show("chenggong");
}
}
}
catch(IsolatedStorageException ex)
{
MessageBox.Show(ex.ToString());
}
}private void button3_Click(object sender, RoutedEventArgs e)
{
try
{
using (IsolatedStorageFile userfile = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream filestream = userfile.OpenFile("imgXml.xml", FileMode.Open, FileAccess.Read))
{
StreamReader str = new StreamReader(filestream);
TextBox textbox = new TextBox();
textbox.Text = str.ReadToEnd().ToString();
textbox.Height = 350;
this.LayoutRoot.Children.Add(textbox);
str.Close();
}
}
}private void button4_Click(object sender, RoutedEventArgs e)
{
XDocument imgXml = null;
try
{
using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream("imgXml.xml", FileMode.Open, file))
{
imgXml =XDocument.Load(fileStream);
XElement new1 = new XElement("img", new XElement("source", "11111"), new XElement("width", "222"), new XElement("height", "555"));
imgXml.Root.Add(new1);
imgXml.Save(fileStream);
fileStream.Close();
MessageBox.Show("添加成功");
}
}
}
catch (IsolatedStorageException ex)
{
MessageBox.Show(ex.ToString());
}
}<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!--这是一个XML文件-->
<imgBox>
<img>
<source>asdsad</source>
<width>150</width>
<height>150</height>
</img>
</imgBox><?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!--这是一个XML文件-->
<imgBox>
<img>
<source>asdsad</source>
<width>150</width>
<height>150</height>
</img>
</imgBox><?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!--这是一个XML文件-->
<imgBox>
<img>
<source>asdsad</source>
<width>150</width>
<height>150</height>
</img>
<img>
<source>11111</source>
<width>222</width>
<height>555</height>
</img>
</imgBox><?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!--这是一个XML文件-->
<imgBox>
<img>
<source>asdsad</source>
<width>150</width>
<height>150</height>
</img>
<img>
<source>11111</source>
<width>222</width>
<height>555</height>
</img>
</imgBox>