关于C# XmlDocument方法Load加载流后自动释放流的解决方法

在实际应用doc.Load(Request.InputStream)的时候,doc.Load方法内置默认释放流

造成再次度Request.InputStream的时候,代码报错

 

替换方法:

XmlDocument doc = new XmlDocument();
Stream stream = Request.InputStream;
byte[] bytes = new byte[stream.Length];
stream.Read(bytes, 0, bytes.Length);

// 设置当前流的位置为流的开始
stream.Seek(0, SeekOrigin.Begin);
doc.LoadXml(Encoding.UTF8.GetString(bytes));

posted @ 2015-03-26 17:10  kiddy-star  阅读(2921)  评论(0编辑  收藏  举报