Link to home
Start Free TrialLog in
Avatar of schubduese
schubdueseFlag for Switzerland

asked on

Write Binary Data into XML with Linq

I read some values of the registry and write them to a XML with Linq. Some Values have binary characters and look like this:

ήì\ÎQÝÜ$Ñ.Ì6Å·xxµ0©ÐQfô:S9}:&X¨Pܾ×CPkÑ

The program crashes when I try to write those values into the XML. How can I write these values into the xml?
Avatar of lludden
lludden
Flag of United States of America image

You will want to MIME encode any binary data you store in an XML document.  See http://www.xml.com/pub/a/98/07/binary/binary.html

I use one of the components in IP!Works (www.nsoftware.com) to do MIME encodings.  If you want to uuencode it instead, there is code here http://www.eggheadcafe.com/PrintSearchContent.asp?LINKID=351

ASKER CERTIFIED SOLUTION
Avatar of Sreedhar Vengala
Sreedhar Vengala
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of schubduese

ASKER

Could you give me a C# example?

Do I have to check every reg entry I read for bin values?
I can write the Data Base64 Encoded with this:

        public static string Encode(string str)
        {
            byte[] encbuff = System.Text.Encoding.UTF8.GetBytes(str);
            return Convert.ToBase64String(encbuff);
        }

That means the routine wich Shows the XML in the Application needs this routine:

        public string Decode(string str)
        {
            byte[] decbuff = Convert.FromBase64String(str);
            return System.Text.Encoding.UTF8.GetString(decbuff);
        }

right?

That means writing the binary into the XML as it is, doesn't work?
There we go with the next Error Message

The Key which failed, works now. But if I scan HKLM\Software\Windows\CurrentVersion it fails and says that the binary value (hex code 0xFFFF) is not a valid sign!

Any help on this?