Connecting Tech Pros Worldwide Forums | Help | Site Map

Convert XML file data to byte array by FromBase64String passing(string xmlData)

Newbie
 
Join Date: Jan 2008
Posts: 1
#1: Jan 30 '08
I've a xml file.I'm taking its data passing it to a method in string form and converting that string "xmlData" to a array of bytes by Convert.FromBase64String(xmlData) but I'm getting a exception "Invalid character in Base-64 string."

My code is like this.

XmlTextReader xmlReader = new XmlTextReader(XML_LAYOUT_FILE_PATH);
XmlDocument doc = new XmlDocument();
doc.Load(xmlReader);
StringWriter writer = new StringWriter();
XmlTextWriter xmlWriter = new XmlTextWriter(writer);
doc.WriteTo(xmlWriter);

string xmlData = writer.ToString();

byte[] userSettings = Convert.FromBase64String(xmlData);---------Exception is thrown here.

Here XML_LAYOUT_FILE_PATH is the xml file location.

So anybody can suggest some solution as to why this exception is coming and what is the solution to it.

My xml file is like this.

<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:clr="http://schemas.microsoft.com/soap/encoding/clr/1.0" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
------------------------
------------------------
Content of file
-----------------------
----------------------
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>


Does this <SOAP-ENV--------> tag is the problem?
Reply