Getting a String into a Stream

Working on a demo using the Office 2007 XML File Formats Code Snippets that I worked on a while back, and needed to get a String value into a Stream--the snippet requires a Stream parameter, and I had a ribbon stored as a project resource (so I get it as a string). I tried several different techniques before I finally gave up and used code like this:

Imports System.Text

Dim stream As New MemoryStream( _
 ASCIIEncoding.Default.GetBytes(My.Resources.CustomUI))

It feels ugly, but it appears to be the only real way to do it.

Published Tuesday, September 05, 2006 12:33 PM by KenG
Filed under:

Comments

Friday, September 15, 2006 11:20 AM by Michael S. Kaplan

# re: Getting a String into a Stream

You could probably pick a better encoding than ASCII, of course. :-)
Tuesday, September 19, 2006 4:08 PM by KenG

# re: Getting a String into a Stream

Michael:

Great to hear from you. Been a long time (Amsterdam, summer 2005?) In any case, of course, you're right (as always). But it worked! Argh. Now I have to revise the stupid code...