Your sample link is exactly what you need, but you need to get information from a MemoryStream instead of an existing file.
You can turn a string directly into a Stream using this:
MemoryStream memStr = MemoryStream(UTF8Encoding.Default.GetBytes("asdf"));
However, you can shorten this by simply turning the string into a byte array , avoiding the need to make Stream as a whole:
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding(); Byte[] bytes = encoding.GetBytes(yourString);
source share