Reading XML file on server without saving it
I am uploading xml file to asp.net. what i want to do is read the file and convert it to xmldoc and send it to one webservice without saving the xml file on the server. Is it possible? If so, can anyone help me with the code. The code I have written so far is below
HttpPostedFile myFile = filMyFile.PostedFile;
int nFileLen = myFile.ContentLength;
if (nFileLen > 0)
{
byte[] myData = new byte[nFileLen];
myFile.InputStream.Read(myData, 0, nFileLen);
}
+2
a source to share
2 answers
You can load it using the input stream of the published file, for example:
XmlDocument doc = new XmlDocument();
doc.Load(myFile.InputStream);
In this case, .Load(Stream)
overload isXmlDocument
used .
+6
a source to share
Using the ASP.NET FileUpload control <asp:FileUpload>
, you can upload the uploaded file as follows. Shows the loading of XmlDocument and XDocument.
using (MemoryStream stream = new MemoryStream(fileUpload.FileBytes))
{
XmlDocument document = new XmlDocument();
document.Load(stream);
stream.Position = 0; // return to beginning for demo
XDocument xdocument = XDocument.Load(XmlReader.Create(stream));
}
0
a source to share