Take the 2-minute tour ×

I need to create a .doc document in C# with specific rtf format. I have a document that I need to replicate in my code but I don't know how to view this documents rtf representation? I don't think copying the content to RichTextBox will help cause I need margin settings and other document, not content, related settings to replicate. Any ideas?

Thank you.

share|improve this question

2 Answers 2

You can save your Word document as RTF which should retain any formatting and style that RTF is able to represent (which should be everything as RTF gets updated with every Word version too).

But don't expect the code to be readable, nicely structured or usable as a basis for your export.

share|improve this answer
...and then, open the RTF file in notepad and take a deep breath. Trying to produce modern Word RTF files is a real nightmare. You should consider using the DOCX format instead, for which there are APIs for .NET. –  Pierre Arnaud Jan 19 '10 at 15:31
Thanks guys. I guess this will not be easy. The document I'm creating doesn't need to be a modern Word file, in fact I'm creating an rtf that I'm saving as .doc. I guess it's going to be a lot of experimenting until I get it to work. –  electro Jan 19 '10 at 15:55
That's something you shouldn't do. This might work but it's not guaranteed (there are different programs used to open doc files, always remember that) and there are different file extensions for doc/rtf for a reason. Don't fake document types just to have some feature named "export as word document". –  Mario Apr 2 '11 at 11:43

You can use one of the following libraries:

  1. http://sourceforge.net/projects/netrtfwriter/
  2. http://www.codeproject.com/KB/string/gioswordnetlibrary.aspx
  3. http://www.codeproject.com/KB/string/nrtftree.aspx

But FIY rtf format isn't simple one with many tricky points in building document in this format. I recommend you to use OpenXML (.docx) format using OpenXML SDK - it provides API to traverse through DOM tree on document and modify it.

If you don't mind adding big dependency to your code you can use COM+ Interop to work with MS Word application instance to generate document you want. Or use it to convert OpenXML document into rtf one.

share|improve this answer

Your Answer


