DotNetT2 Dark_1200x303

With the R2 2021 release of our Telerik products, we added the DOC and DOT file formats support (import only) to the RadWordsProcessing library.

What Are DOC and DOT File Formats?

DOC is the Word 97-2003 Binary File Format, developed by Microsoft for saving documents with the .doc extension, and DOT (.dot) is the document template for the same file format.

Now both of them are supported by RadWordsProcessing.

In 2007, with the release of Microsoft Word 2007, the DOC format was replaced by a more open and structured DOCX format (DOT became DOTX), part of Microsoft Office Open XML specification (aka OOXML or OpenXML), but even today both the DOC and DOT formats are still widely used.

DOC/DOТ and RadWordsProcessing

RadWordsProcessing library through its format providers (check Formats and Conversion help article) lets you import different document formats (DOCX, RTF, HTML, Plain text, and now DOC & DOT) into its RadFlowDocument model and export this document data to DOCX, RTF, HTML, Plain text and PDF file format.

Project Setup: Adding New References

In addition to the currently required references, there is a new one responsible for importing DOC and DOT file formats.

There are two approaches you can use to reference the new assembly: via NuGet package or by direct assembly reference.

Reference via NuGet:

.NET Framework:
Telerik.Windows.Documents.Flow.FormatProviders.Doc package

Packages_NetFramework_nuget - Telerik.Windows.Documents.Flow.FormatProviders.Doc

.NET Standard:
Telerik.Documents.Flow.FormatProviders.Doc package

Packages_NetStandard_nuget - Telerik.Documents.Flow.FormatProviders.Doc

.NET Standard for Xamarin:
Telerik.UI.for.Xamarin.Documents.Flow.FormatProviders.Doc package

Packages_NetStandard_Xamarin_nuget - Telerik.UI.for.Xamarin.Documents.Flow.FormatProviders.Doc

Check the NuGet Packages help article for more detailed information on the different NuGet packages related to Telerik Document Processing.

Add assembly reference:

.NET Framework:
Telerik.Windows.Documents.Flow.FormatProviders.Doc.dll

Packages_NetFramework_dll - Telerik.Windows.Documents.Flow.FormatProviders.Doc.dll

.NET Standard:
Telerik.Documents.Flow.FormatProviders.Doc.dll

Packages_NetStandard_dll - Telerik.Documents.Flow.FormatProviders.Doc.dll

Now that the references are added, we’re ready to examine the new format provider class.

Using DocFormatProvider

DocFormatProvider makes it easy to import a DOC or DOT file into a RadFlowDocument, preserving the entire document structure and formatting. You can easily import a RadFlowDocument from DOC or DOT document format in the following manner:

RadFlowDocument document;
string pathToDoc = "SampleFile.doc"; // "SampleFile.dot"
using (Stream inputStream = File.OpenRead(pathToDoc))
{
DocFormatProvider docFormatProvider = new DocFormatProvider();
document = docFormatProvider.Import(inputStream);
}

You can find more information in the Using DocFormatProvider help article.

Once imported, the RadFlowDocument can be exported as a byte array:

DocxFormatProvider provider = new DocxFormatProvider();
byte[] output = provider.Export(document);

or as any of the supported by the RadWordsProcessing document formats (supported formats).

Features

DocFormatProvider supports features like Text Formatting, Paragraph Options, Page/Section options, Tables, Inline Images, Themes, Hyperlinks, Fields, Headers & Footers, and many others that can be found in the Features help topic.

Converting DOC/DOT to DOCX

RadFlowDocument document;
string pathToDoc = "Legacy.doc"; // "Legacy.dot"
string pathToDocx = "Current.docx";
 
using (Stream inputStream = new FileStream(pathToDoc, FileMode.Open))
{
    DocFormatProvider docFormatProvider = new DocFormatProvider();
    document = docFormatProvider.Import(inputStream);
}
 
using (Stream outputStream = new FileStream(pathToDocx, FileMode.OpenOrCreate))
{
    DocxFormatProvider docxFormatProvider = new DocxFormatProvider();
    docxFormatProvider.Export(document, outputStream);
}

Try RadWordsProcessing Yourself

Get yourself a free trial of Telerik Document Processing today and start developing your apps better, faster, and more easily.

Start My Trial

Share Your Feedback

Let’s continue to build the future of Telerik Document Processing together! So, don’t forget to share your thoughts as a comment below or let us know if you have any suggestions and/or need any features/components by visiting our Telerik Document Processing Feedback Portal and Telerik Document Processing Forum.


profile_pic_cropped
About the Author

Martin Velikov

Martin is a Technical Support Engineer, part of the Document Processing team in Sofia, Bulgaria since July 2019. He is passionate about new technologies and is always on the crest of a wave with the novelties. In his spare time, Martin likes travelling to new destinations and exploring new cultures, hanging out with friends, reading books, practicing sports, and more.

Related Posts

Comments

Comments are disabled in preview mode.