4

I have a active document :

Microsoft.Office.Interop.Word.Document document = Globals.ThisAddIn.Application.ActiveDocument;

How I can convert this to stream?

Or even better, how to send active document to rest web service?

Thanks

mikipero
  • 420
  • 1
  • 6
  • 27

2 Answers2

1

Which rest-service? If it's SharePoint or the like i'm used to just calling the SaveAs function as follows:

Microsoft.Office.Interop.Word.Document document = Globals.ThisAddIn.Application.ActiveDocument;
document.SaveAs("https://www.contoso.sharepoint.com/Documents/Document1.docx");

Edit: P.S. You can serialize anything to Stream. found an answer here

public static MemoryStream SerializeToStream(object o)
{
    MemoryStream stream = new MemoryStream();
    IFormatter formatter = new BinaryFormatter();
    formatter.Serialize(stream, o);
    return stream;
}

public static object DeserializeFromStream(MemoryStream stream)
{
    IFormatter formatter = new BinaryFormatter();
    stream.Seek(0, SeekOrigin.Begin);
    object o = formatter.Deserialize(stream);
    return o;
}
Community
  • 1
  • 1
Fixation
  • 969
  • 6
  • 12
0

Save to a temp file then read file content as required by the rest service, e.g. byte array. Or use Open XML SDK if older Word formats are not required.

user3285954
  • 4,499
  • 2
  • 27
  • 19