?
Solved

Loading byte data to an Xml Document

Posted on 2011-10-12
4
Medium Priority
?
396 Views
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))
                        {
                              xmlDoc.Load(baseMemStream);
                        }

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

0
Comment
Question by:ZURINET
  • 2
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
jagrut_patel earned 1500 total points
ID: 36954165
Try this,

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

HTH!

0
 

Author Comment

by:ZURINET
ID: 36954252
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
				_FileStream.Close();

Open in new window

0
 
LVL 8

Expert Comment

by:jagrut_patel
ID: 36954710
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?

0
 

Author Closing Comment

by:ZURINET
ID: 36960408
Sorry solved it with another solution
0

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Loops Section Overview
Suggested Courses

839 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