How to convert a Document Instance to a FileStream
See the question and my original answer on StackOverflowSomething like this should work:
public class WordGenerator : IDocumentGenerator
{
FileStream IDocumentGenerator.GenerateDocument()
{
object missing = System.Reflection.Missing.Value;
Document adoc = new Document();
adoc.InlineShapes.AddPicture(@"http://localhost:2014/Resources/MG.PNG", ref missing, ref missing, ref missing);
// save the doc file
object fileName = Path.GetTempFileName();
adoc.SaveAs(ref fileName, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
// quit word and release COM objects
object saveChanges = WdSaveOptions.wdDoNotSaveChanges;
adoc.Application.Quit(ref saveChanges, ref missing, ref missing);
Marshal.ReleaseComObject(adoc);
// return the stream
return new FileStream((string)fileName, FileMode.Open);
}
}
and you'll have to delete the temp file sometime in the future.