106

Possible Duplicate:
How do I convert byte[] to stream in C#?

I need to convert a byte array to a Stream . How to do so in C#?

It is in asp.net application.

FileUpload Control Name: taxformUpload

Program

byte[] buffer = new byte[(int)taxformUpload.FileContent.Length];
taxformUpload.FileContent.Read(buffer, 0, buffer.Length);

Stream stream = ConvertToStream(buffer);
Community
  • 1
  • 1
priyanka.sarkar
  • 25,766
  • 43
  • 127
  • 173

3 Answers3

244

Easy, simply wrap a MemoryStream around it:

Stream stream = new MemoryStream(buffer);
Etienne de Martel
  • 34,692
  • 8
  • 91
  • 111
21

In your case:

MemoryStream ms = new MemoryStream(buffer);
Icarus
  • 63,293
  • 14
  • 100
  • 115
5

I am using as what John Rasch said:

Stream streamContent = taxformUpload.FileContent;
paz
  • 520
  • 1
  • 4
  • 11
priyanka.sarkar
  • 25,766
  • 43
  • 127
  • 173