System.IO.Stream stream = Request.InputStream;
stream.Position = 0;//重置流的位置,以便我们可以从头读取
TextReader tread = new StreamReader(stream, System.Text.Encoding.GetEncoding("gb2312"));
XElement doc = XElement.Load(tread);
IEnumerable<XElement> xElement = from xx in doc.Descendants("File")
select xx;
就这么几步 搞了 我两天 终于好了
还是基础方法没找对啊
记录下
//附加文件创建的操作
string path = @"D:/pan/数据接收服务/SaveAlarmRecord.xml";
System.IO.FileInfo fInfo = new System.IO.FileInfo(path);
if (fInfo.Exists)
{
XElement doc_xml = XElement.Load(path);
doc_xml.Add(xElement);
doc_xml.Save(path);
}
else
{
FileStream fs = fInfo.Create();
string xx = "<?xml version='1.0' encoding='gb2312' ?><Alarm></Alarm>";
System.Text.Encoding GB2312 = System.Text.Encoding.GetEncoding("GB2312");
byte[] data = System.Text.Encoding.GetEncoding("GB2312").GetBytes(xx);
fs.Write(data, 0, data.Length);
fs.Flush();
fs.Close();
fs.Dispose();
XElement doc_xml = XElement.Load(path);
doc_xml.Add(xElement);
doc_xml.Save(path);
}