C#创建简单的Xml文件
/// <summary> /// 创建xml文件 /// </summary> /// <param name="xmlDoc">xml</param> /// <returns></returns> public string CreateXml(string xmlDoc) { string filePathName = string.Empty; try { if (Directory.Exists(XMLPath) == false) { Directory.CreateDirectory(XMLPath); } string t1 = "GL"; string t2 = Convert.ToDateTime(DateTime.Now.ToString()).ToString("yyyyMMddHHmmss"); string t3 = DateTime.Now.Millisecond.ToString(); string NewFileName = t1 + t2 + t3 + ".xml"; filePathName = XMLPath + "\\" + NewFileName; XmlDocument XmlDocument = ConvertStringToXml(xmlDoc); StreamWriter sw = new StreamWriter(filePathName, false, new UTF8Encoding(false)); XmlDocument.Save(sw); sw.Close(); bool m_isFileExisted = File.Exists(filePathName); if (m_isFileExisted) { return filePathName; } else { filePathName = ""; } } catch (Exception ex) { filePathName = ""; } return filePathName; }