Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Memory stream to Base64

Posted on 2011-09-29
1
Medium Priority
?
9,245 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

597 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