Solved

Memory stream to Base64

Posted on 2011-09-29
1
5,548 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 74

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

11 Experts available now in Live!

Get 1:1 Help Now