Convert Word doc to RTF in memory

I have a word document that I want to convert to RTF in memory.

So my sample code is like this:

Document doc = new Document(filepath);
string RTF = doc.ConvertToRTF();

or something similar.

I know I can save to disk or stream as RTF format and the convert but is there a easier way?

Hi Nitin,

Thanks for your inquiry. Please use the following code snippet for your requirement. Hope this helps you. Please let us know if you have any more queries.

Document doc = new Document(MyDir + "in.docx");
// Save document to stream as RTF 
MemoryStream rtfStream = new MemoryStream();
SaveOptions options = SaveOptions.CreateSaveOptions(SaveFormat.Rtf);
doc.Save(rtfStream, options);
rtfStream.Position = 0;
StreamReader reader = new StreamReader(rtfStream);
string text = reader.ReadToEnd();
reader.Close();

that’s perfect! Thank you!

Hi Nitin,

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.