Loading byte data to an Xml Document

Posted on 2011-10-12
Last Modified: 2012-05-12
Dear all
Give the class below

I need a way to extract the Data from the DownloadFile class
and assign it or load the data to an xml document. See the code below for details

Somehow I need to achive this

using (MemoryStream baseMemStream = new MemoryStream(newDownLoadFile.[k].data))

Thanks in Advance
public class DownloadFile 
	public byte[] Data; 
	public String Filename; 

DownloadFile[] newDownLoadFile = GetMyProtocol( String customerID, DateTime CreateDate,boolean SavedData );

Until now I have tried to assign the data to an xml document
XmlDocument myXmlDoc = new XmlDocument();
if (newDownLoadFile.Length > 0)
	for (int k = 0; k < newDownLoadFile.Length; k++)
	myXmlDoc.load = newDownLoadFile[k].Data); // this is not working I need a stream

Open in new window

Question by:ZURINET
    LVL 8

    Accepted Solution

    Try this,

    MemoryStream stream = new MemoryStream();
    stream.Write(newDownLoadFile[k].Data, 0, newDownLoadFile[k].Data.Length);



    Author Comment

    Hi jagrut

    Thanks for the feeback..
    Tried it ... getting some erros..  (Root element is missing.)

    Any Ideas..  Notwitstanding that I can use the code below to write it to file.. but need to a method that will retrun xml document..

     ByteArrayToFile(pathNew + varIncrement, newDownLoadFile[k].Data);
    public void  ByteArrayToFile
    // Open file for reading
    				System.IO.FileStream _FileStream = new System.IO.FileStream(_FileName, System.IO.FileMode.Create, System.IO.FileAccess.Write);
    				// Writes a block of bytes to this stream using data from a byte array.
    				_FileStream.Write(_ByteArray, 0, _ByteArray.Length);
    				// close file stream

    Open in new window

    LVL 8

    Expert Comment

    The error suggest that XML data that you get in byte array is not XML compliant.
    BTW, at which line of code you get this error?


    Author Closing Comment

    Sorry solved it with another solution

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (…
    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now