These days, a large number of articles, blogs, and documentation are written in Markdown (MD) format. However, the Markdown syntax often becomes difficult to remember and write for large-sized documents. To make things easier, you can write content in MS Word and then convert DOCX or DOC document to Markdown. To automate Word to Markdown conversion, this article covers how to convert Word documents to Markdown (.md) files using C#.
- Word to Markdown Converter Library
- Convert a Word Document to Markdown
- Customize Word to Markdown Conversion
C# Word to Markdown Converter Library
Aspose.Words for .NET is designed to create and manipulate Word documents from within .NET applications. In addition, it provides a built-in converter to convert MS Word documents to other formats. We will use this API to convert Word documents to Markdown format. You can download the API’s DLL or install it from NuGet using the package manager console.
PM> Install-Package Aspose.Words
Convert a Word Document to Markdown in C#
The following are the steps to convert a Word DOCX file to Markdown format in C#.
- Load the Word file using Document class.
- Convert Word file to Markdown format using Document.Save(string) method.
The following code sample shows how to convert a DOCX file to Markdown format using C#.
Customize Word to Markdown Conversion
You can also customize the default behavior of Word to Markdown conversion using different options. For example, you can set the alignment of the content in the tables, specify a folder to keep images, and so on. The following are the steps to customize Word to Markdown conversion.
- Load the Word document using Document class.
- Create an object of MarkdownSaveOptions class.
- Set desired options such as MarkdownSaveOptions.ImagesFolder.
- Convert Word document to Markdown using Document.Save(string, MarkdownSaveOptions) method.
The following code sample shows how to customize DOCX to Markdown conversion using C#.
Get a Free API License
You can use Aspose.Words for .NET without evaluation limitations using a temporary license.
In this article, you have learned how to convert Word DOCX/DOC files to Markdown (.md) in C#. Moreover, you have seen how to customize Word to Markdown conversion using different options. You can also explore other features offered by Aspose.Words for .NET using the documentation. Also, you can feel free to ask your questions via our forum.