2

In My code try:

data expected

Stream Content

engine.SetDocument((MemoryStream)content); //No work

Or

var a = new MemoryStream();
engine.SetDocument(content.CopyTo(a)); //Error 
LarsTech
  • 80,625
  • 14
  • 153
  • 225
Andres Carvajal
  • 141
  • 1
  • 2
  • 13
  • Looks like it wants a MemoryStream. Try `SetDocument(a);` – LarsTech Apr 19 '16 at 14:52
  • @AndresCarvajal `Stream` is abstract - so it must be something more specific in reality. It may or may not be a `MemoryStream`, so casting is not safe. What are you needing to do that requires a `Memorystream`? – D Stanley Apr 19 '16 at 14:57

2 Answers2

8

CopyTo is a void method so returns nothing, try the following:

var a = new MemoryStream();
content.CopyTo(a);
engine.SetDocument(a);
Simon
  • 1,081
  • 9
  • 14
3
using (MemoryStream ms = new MemoryStream())
using (FileStream file = new FileStream("file.bin", FileMode.Open, FileAccess.Read)) 
{
   byte[] bytes = new byte[file.Length];
   file.Read(bytes, 0, (int)file.Length);
   ms.Write(bytes, 0, (int)file.Length);
}