4

Given the following code fragment

wordApp.Documents.Open(FileName: wordDoc, Visible: false); 

if (wordApp.Documents.Count > 0)
{
      _Document thisDoc = wordApp.ActiveDocument;
      thisDoc.SaveAs(FileName: rtfDoc, FileFormat: WdSaveFormat.wdFormatRTF);

Can anyone suggest a method to perform this conversion without saving to disk?

I want the raw text of the rtf document in memory, perhaps as a StringBuilder object.

Chris
  • 8,527
  • 10
  • 34
  • 51
Hugh Jones
  • 2,706
  • 19
  • 30

1 Answers1

2

Unfortunately, this is just not possible.

With Office Interop, there is NO way to use such methods (Open, SaveAs) with something else than a valid file (so it must exist or be saved on the disk or somewhere else).

What you need to keep in mind, is that Interop allows you to do at most what you could do with the Office application itself. And there is currently no way to work with MemoryStream with Office Application, just existing files.

Working with MemoryStream is possible with OpenXML SDK. Unfortunately, OpenXml SDK does not provide method to convert to Rtf format.

See also: How can I form a Word document using stream of bytes

Community
  • 1
  • 1
Chris
  • 8,527
  • 10
  • 34
  • 51