DOC to ODT – Convert DOC to ODT in C#

DOC to ODT conversion

DOC files are created to save various documents, including letters, resumes, essays, and invitations. The DOC file was designated as Microsoft Word’s primary format in 1983 used the same format until Word 97. You can also open DOC files with other word processors, but some of the formattings of the original documents may be altered or lost. On the other hand, ODT files are types of documents created with word processing applications that are based on OpenDocument Text File format. These are created with word processor applications such as free OpenOffice Writer and can also hold content such as text, images, objects, and styles. In this article, we are going to discuss the steps on how to convert DOC file format to ODT without losing any content or formatting using .NET REST API.

Word Processing API

In order to process Word documents including DOC, DOT, DOCX, DOTX, DOTM, ODT, OTT, etc, and other major formats, we have specifically created Aspose.Words Cloud. It is based on REST architecture and can be used on several platforms (Windows, Linux, iOS, Android). You can use it to create, edit, merge, split, compare and convert Word documents to other Supported File Formats.

Furthermore, to facilitate our customers, we have created lightweight programming language-specific SDKs that provide a language-level interface to access Aspose.Words Cloud API and utilize the corresponding document-processing functionality in a manner consistent with language standards. So let’s focus on Aspose.Words Cloud SDK for .NET in this article.

Installation

To get started with using the Cloud SDK, installation is the first step. It is available for download NuGet and GitHub. In order to install the SDK from NuGet, please consider executing the following command in the terminal.

nuget install Aspose.Words-Cloud

NuGet Package Manager

You may also consider executing the following command in Package Manager Console in Visual Studio to fetch & reference Aspose.Words assembly in your project.

PM> Install-Package Aspose.Words-Cloud

Visual Studio

Another approach is the installation directly within Visual Studio solution:

  1. Open the Solution Explorer.
  2. Expand the project and Right-click Packages folder within your solution.
  3. Select Manage NuGet Packages… option
  4. Click on the Browse tab and search for “Aspose.Words-Cloud“.
  5. Click on the Aspose.Words-Cloud package, select the appropriate version in the right-tab and click Add Package button.
Aspose.Words-Cloud
Image 1:- Aspose.Words Cloud as NuGet package.

Cloud Dashboard

Once the SDK has been installed, now we need to create a free subscription account over Aspose.Cloud dashboard. The subscription is free and you do not need to even provide your credit card or other payment details. Furthermore, please note that under a free subscription account, you can perform up to 150 Free document processing requests.

So if you have GitHub or Google account, simply Sign Up. Otherwise, click on the Create a new Account button and provide the required information. Now login to the dashboard using credentials and expand the Applications section from the dashboard and scroll down towards the Client Credentials section to see Client ID and Client Secret details.

Client Credentials
Image 2:- Client Credentials at Aspose.Cloud dashboard.

DOC to ODT in C#

Now that all setup and account configuration steps are complete, we can follow the instructions given below to convert the DOC file to ODT format using the C# .NET code snippet.

  • The first step is to create Configuration object using Client credentials
  • Secondly, initialize WordsApi instance while passing Configuration object as argument
  • Thirdly, load input DOC file into stream object
  • Now initialize ConvertDocumentRequest instnace which takes document stream and resultant format as arguments
  • In order to perform the conversion, call ConvertDocument(…) method of WordsApi
  • Since the resultant file is in Stream instance, so we will use saveToDisk(…) method to save ouptut on local drive
DOC to ODT preview
Image 2:- DOC to ODT conversion preview.

Please download the sample files used in the above example from sample.doc and conveted.odt.

Convert DOC to ODT using cURL

Owing to the REST architecture of Aspose.Words Cloud, it can also be accessed through the cURL commands. But before proceeding, we need to authenticate the user based on Client credentials. Therefore, first, we need to generate a JWT access token based on our personalized client credentials. Please execute the following command for JWT access token generation.

curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=4ccf1790-accc-41e9-8d18-a78dbb2ed1aa&client_secret=caac6e3d4a4724b2feb53f4e460eade3" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"

Now execute the following command to perform the conversion operation:

curl -X PUT "https://api.aspose.cloud/v4.0/words/convert?format=ODT&outPath=Converted.odt&fileNameFieldValue=sourceFilename" \
-H  "accept: application/octet-stream" \
-H  "Authorization: Bearer <JWT Token>" \
-H  "Content-Type: multipart/form-data" \
-d {"document":{}}

Conclusion

In this blog, we have discussed the details on how we can convert DOC files to ODT format using the C# .NET code snippet and through the cURL command. Please be noted that all our SDKs are offered under an MIT license, so a complete code snippet of Aspose.Words Cloud SDK for .NET can be downloaded from GitHub. In case you encounter any issue while using the API or you have any related query, please feel free to contact via the Free Support forum.

Related links

We also recommend visiting the following links to learn more about