没有合适的资源?快使用搜索试试~ 我知道了~
net c# 读写xml 的实例, 有两种写方式。以及对XML的修改,删除操作
资源推荐
资源详情
资源评论
添加引用 using System.IO;
using System.Xml;
//获取根目录 bin\Debug目录地址
public static readonly string SYS_CONFIGURE_URL = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
//获取xml文件地址
private static string fileName = Constants.SYS_CONFIGURE_URL + "\\ConfigurePrint.xml";
读取XML
if (File.Exists(fileName))
{
ds = new DataSet();
ds.ReadXml(fileName);
if (ds.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
this.cboProductName.Items.Add(ds.Tables[0].Rows[i]["PRODUCTNAME"].ToString());
}
this.cboProductName.SelectedIndex = 0;
}
}
using System.Xml;
//获取根目录 bin\Debug目录地址
public static readonly string SYS_CONFIGURE_URL = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
//获取xml文件地址
private static string fileName = Constants.SYS_CONFIGURE_URL + "\\ConfigurePrint.xml";
读取XML
if (File.Exists(fileName))
{
ds = new DataSet();
ds.ReadXml(fileName);
if (ds.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
this.cboProductName.Items.Add(ds.Tables[0].Rows[i]["PRODUCTNAME"].ToString());
}
this.cboProductName.SelectedIndex = 0;
}
}
写XML 方法一 直接覆盖原有的。
if (!File.Exists(fileName))
{
FileStream fs = File.Create(fileName);
fs.Close();
}
XmlDocument xDoc = new XmlDocument();
XmlTextWriter xw = new XmlTextWriter(fileName, Encoding.Default);
xDoc.WriteTo(xw);
xw.WriteStartElement("WEBPROXY");
xw.WriteAttributeString("RICARIOUS", this.chkRicarious.Checked.ToString());
xw.WriteAttributeString("ADDRESS", this.userIPControl1.Text);
xw.WriteAttributeString("PORT", this.txtPort.Text);
xw.WriteAttributeString("VALIDATE", this.chkValidate.Checked.ToString());
xw.WriteAttributeString("USERNAME", this.txtUserName.Text);
xw.WriteAttributeString("PASSWORD", this.txtPassword.Text);
if (this.radLAN.Checked)
xw.WriteAttributeString("NETWORK", "2");
else
xw.WriteAttributeString("NETWORK","1");
xw.WriteEndElement();
剩余7页未读,继续阅读
资源评论
nigerenz
- 粉丝: 6
- 资源: 14
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功