您的位置:首页 > 其它

[winform]操作文件与xml常用方法

2014-12-19 19:20 423 查看
bin/debuge下面
1.文件夹移动:log复制到Log2
System.IO.Directory.Move("Log", "Log2");
2.判断文件夹是否存在不存在创建文件夹:
if (!Directory.Exists("Log"))
{
Directory.CreateDirectory("Log");
}
3.判断文件是否存在不存在床架文件
DateTime now = DateTime.Now;
string logFileName = now.ToString("yyyyMMdd") + ".txt";
string fullName = "Log\\" + logFileName;
if (!File.Exists(fullName))
{
File.Create(fullName);
}
4.打开wod文件
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.FileName = @"D:\我的XXX.docx";
// proc.StartInfo.Arguments = @"D:\我的XXX.docx";
proc.Start();
5.获取路径路径到BIN
System.AppDomain.CurrentDomain.BaseDirectory;
6. CDATA 怎么产生这样的数据?
<XXZY1><![CDATA[郑亚敏1]]></XXZY1>

XmlNode objNode = xmlDocument.DocumentElement.SelectSingleNode("//CommitUnitName");
XmlCDataSection CData = xmlDocument.CreateCDataSection("<郑亚敏");
objNode.InnerXml = "";//清空节点里面的数据
(objNode as XmlElement).AppendChild(CData);

7.修改一个节点的Name值
XmlNode xn = xmlDocument.DocumentElement.SelectSingleNode("//CommitUnitName");
XmlHelper.AppendAttr(xn, "Name", "郑亚敏");

<XmlTextTag>
<CommitUnitName Name="郑亚敏11111">
</CommitUnitName>
</XmlTextTag>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: