标签:指定 file 保存 1.0 test 路径 dir 字符 directory
/// <summary>
/// 将XML字符串写入到XML文件
/// </summary>
/// <param name="strXML"></param>
private int WriteStrToXML(string strXmlName, string strXML)
{
try
{
string filepath = System.Web.HttpContext.Current.Server.MapPath("~/CatitalXML");
if (!Directory.Exists(filepath))
Directory.CreateDirectory(filepath);
filepath = filepath + "/" + DateTime.Now.ToString("yyyy-MM-ddHHmmss") + strXmlName + ".XML";
XmlDocument xdoc = new XmlDocument();
xdoc.AppendChild(xdoc.CreateXmlDeclaration("1.0", "UTF-8", null));//xml文件头
xdoc.LoadXml(strXML);
xdoc.Save(filepath);
return 0;
}
catch (Exception)
{
return -1;
}
}
将XML字符串写入到XML文件并保存到指定路径
标签:指定 file 保存 1.0 test 路径 dir 字符 directory
原文地址:https://www.cnblogs.com/nayilvyangguang/p/9981536.html