Solved

Memory stream to Base64

Posted on 2011-09-29
1
5,842 Views
Last Modified: 2012-05-12
How can I do these 3 things
1) Use a memorystream

MemoryStream m = new MemoryStream();

serialize object into stream.

2) Use MemoryStream.ToArray()
which will convert your memorystream into a byte []

3) Call Convert.ToBase64(yourbytes) which will return you a byte []

Thanks in Advance
0
Comment
Question by:ZURINET
1 Comment
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 36816891
Perhaps something like this?

using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace _27361478
{
    class Program
    {
        static void Main(string[] args)
        {
            MemoryStream ms = new MemoryStream();
            BinaryFormatter serializer = new BinaryFormatter();
            Car c = new Car() { Make = "Honda", Model = "Civic" };

            serializer.Serialize(ms, c);
            byte[] byteArr = ms.ToArray();
            string binStr = Convert.ToBase64String(byteArr);
            byte[] binary = System.Text.Encoding.ASCII.GetBytes(binStr);
        }
    }

    [Serializable()]
    public class Car
    {
        public string Make { get; set; }
        public string Model { get; set; }
    }
}

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows Service to Receive TCP Packets 4 120
Linq Help 1 35
how to read json value 2 30
Error on link 14 37
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…
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 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