winform中读取嵌入的xml文件

 System.Reflection.Assembly thisExe = System.Reflection.Assembly.GetExecutingAssembly();
string xmlPath = string.Empty; 
xmlPath = "AutoCode.BLL.xml";// "名称空间.文件名.xml" 注意xml必须放到项目的根目录,放入文件夹里无效。记得xml文件要是utf-8编码
 System.IO.Stream xmlr = thisExe.GetManifestResourceStream(xmlPath);
StreamReader sr = new StreamReader(xslr,Encoding.UTF8);

string str= sr.ReadToEnd();

File.Delete("temp.xml");
File.AppendAllText("temp.xml", str, Encoding.UTF8);//写到xml文件

你可能感兴趣的:(WinForm)