I will transfer the xml file as follows:
File1.PostedFile.InputStream //reading xml file..... public static void readXMLOutput(Stream stream) { System.Xml.Linq.XDocument xml = System.Xml.Linq.XDocument.Load(stream); var query = from p in xml.Element("ste").Element("Application") //where (int)p.Element("Id") == 1 select Page; foreach (var record in query) { Response.Write("dfe") + record.Element("dfe").Value; }
Error:
Error 1 The best overloaded method match for 'System.Xml.Linq.XDocument.Load (string)' has some invalid argumentscannot convert from 'System.IO.Stream' to 'string'
Error 1 The best overloaded method match for 'System.Xml.Linq.XDocument.Load (string)' has some invalid arguments
cannot convert from 'System.IO.Stream' to 'string'
Are you using .NET 3.5 by accident? XDocument.Load(Stream)apparently only in .NET 4.
XDocument.Load(Stream)
You might want to use an overload that acceptsXmlReader (which is supported in 3.5).
XmlReader
EDIT: Code Example:
static XDocument LoadFromStream(Stream stream) { using (XmlReader reader = XmlReader.Create(stream)) { return XDocument.Load(reader); } }
XDocument.Load(Stream) .NET 4. :
public static void readXMLOutput(Stream stream){ string streamContents; using(var sr = new StreamReader(stream)){ streamContents = sr.ReadToEnd(); } var document = XDocument.Parse(streamContents); }