Solved

MemoryStream Convert.ToBase64String

Posted on 2011-09-28
5
547 Views
Last Modified: 2012-05-12
Hallo
Need to convert a string to  base64 stream
any Idea..?
see code below

Thanks
StreamReader reader = new StreamReader(@"C:\Inetpub\ftproot\100.xml");
string parseInvResult = reader.ReadToEnd();
byte[] binaryData 
using (MemoryStream basePdfMemStream = new MemoryStream(Convert.ToBase64String(parseInvResult)))
				{
					binaryData = basePdfMemStream.ToArray();
				}

Open in new window

0
Comment
Question by:ZURINET
  • 3
  • 2
5 Comments
 
LVL 23

Expert Comment

by:wdosanjos
Comment Utility
Base 64 is used to represent binary data as a string not the other way around.  Please clarify.
0
 

Author Comment

by:ZURINET
Comment Utility
Hi wdosanjos

I have a need to provide base64 string for the datatype

byte[] Data;

in any XML file..

I have an xml document; I need to convert to base64 and insert it in into another xml document
i.e soap body  element.. defined as base64

what should be the best approach?

0
 
LVL 23

Accepted Solution

by:
wdosanjos earned 500 total points
Comment Utility
When dealing with XML files, generally you don't need to convert to base64 manually as the XML classes will do that for you.  So, I believe the following should be enough.

StreamReader reader = new StreamReader(@"C:\Inetpub\ftproot\100.xml");
string parseInvResult = reader.ReadToEnd();
byte[] binaryData = System.Text.Encoding.UTF8.GetBytes(parseInvResult);

Open in new window

0
 

Author Closing Comment

by:ZURINET
Comment Utility
Answer not complete
0
 
LVL 23

Expert Comment

by:wdosanjos
Comment Utility
Hi ZURINET,

What's missing?

Regards.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

728 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

9 Experts available now in Live!

Get 1:1 Help Now