Work with Word Documents in C#


Work with Word Documents in C#

Open, generate, edit, split, merge, compare and convert a Word document in C#. It's easy for C# developers to manipulate Microsoft Word documents.
Simply integrate our Cloud API into your applications to get full-featured Word API that allows you to work, manipulate and integrate documents into your C#, ASP.NET and all other .NET apps including web, mobile, desktop, gaming, IoT, cloud, and microservices.
The main usage of this library is to create, open, edit, split, convert documents in different file formats such as DOCX, HTML, PDF, DOC, JPG, etc.
Cloud API gives you a library to do tasks programmatically in C# such as:

  • Add text in a Word document.
  • Search and replace text in Word documents.
  • Insert a table of contents.
  • Generate reports and mail merge.
  • Insert images into files.
  • Add watermark.

This API is the most agile method for a .NET developer to speed up the process of working with documents while developing a .NET app. API takes care of low-level details to make requests and handle responses. And this lets you focus on writing code specific to your particular project.

Note: Install NuGet package to start working with documents.

  • Main
  • Convert
  • Structure
  • Content
  • Tables
  • MailMerge
  • Other
  • Plugins


.NET Framework 2.0 or .NET Standard 2.0

Supported Document Formats

You can both read and write documents in: DOCX, DOC, PDF, MD, RTF, DOCM, DOTX, DOT, DOTM, ODT, OTT, XML, HTML, MHTML, XHTML, TXT.
The write-only formats are: XPS, OpenXPS, PS, JPEG, PNG, BMP, SVG, TIFF, EMF, PCL, EPUB.
The read-only formats are: MOBI, CHM.
For more details, please check Supported File Formats.

Cloud features for C#

  • Open, create and edit paragraphs and text.
  • Open, create and edit images, text boxes and shapes.
  • Open, create and edit tables including rows and cells.
  • Open, create and edit fields, form fields, hyperlinks and bookmarks.
  • Open, create and edit document sections, headers and footers.
  • Open, create and edit footnotes, endnotes and comments.
  • Convert documents between several popular file formats.
  • Load and save HTML/XHTML.
  • Render individual shapes from a document into raster or vector images.
  • Add and update all character formatting including fonts, colors, effects, borders, shading, etc.

Edit a Word document in C#

Cloud API provides a solution to edit a Word document with C# and all other .NET apps including web, mobile, desktop, gaming, IoT, cloud, and microservices. Using C#, you can edit an existing Word document to correct spellings or add new content to a file. Also, it's used to access and to modify document’s elements as well as their formatting.
Assume that you want to update the text in first paragraph of first section in your Word document that you have created before. So, you will need to specify the index of the first section and the first paragraph.

Create a new Word document in C#

Cloud API includes all the methods and properties to create a Word document from scratch. It allows you to insert elements such as text, paragraphs, checkboxes, tables, lists, images and all other objects that a Word document can contain.

Parse a Word Document using C#

Parse a Word document by extracting a document’s content as a plain text and save it into a .txt file.

Convert a Word Document with Cloud API

Along with the features to create and manipulate Word documents, cloud API allows you to convert a Word document from DOCX to another file format including (but not limited to) HTML, PDF, XPS, EPUB and image formats such as PNG, JPEG or BMP.

Split a Word file into multiple PDF files

  • Divide multi-page Word documents into separate Word documents.
  • Split by page number, odd/even pages and by page range.
  • Keep style and layout of the root document.

Rendering documents in Cloud

Rendering is used to define the method of converting a document into a paginated file format.
Our API allows you to perform the following:

  • Render a page to a specified format.
  • Render a table to a specified format.
  • Render a paragraph to a specified format.
  • Render drawing objects (e.g. oval, rectangle, line) to a specified format.
  • Render math objects to a specified format.
  • Render pages of a Word document to image formats including PNG, EMF, JPEG and GIF.

Swagger UI

You can use Swagger UI to visualize and interact with APIs resources.

Convert PDF to Word in C#

The following code sample shows how to convert PDF to DOCX in the Cloud and save the result to a local file:

Convert PDF to DOCX
var appKey = "##################";
var appSid = "####-####-####-####-####";
var wordsApi = new WordsApi(appKey, appSid);

var request = new ConvertDocumentRequest(File.OpenRead("sample.pdf"), "docx");
var result = wordsApi.ConvertDocument(request);
using (var file = new FileStream("sample.docx", FileMode.Create, FileAccess.Write))

Advanced Features

How to open and edit a DOCX document in C#

  1. Install NuGet package or use the direct download.
  2. Go to the Aspose Cloud Dashboard.
  3. Create a new Account to access all applications and services or Sign In to your existing account.
  4. Click on Applications in the left menu to get Client Id and Client Secret.
  5. Upload a DOCX file to the Cloud Storage or use directly in the request body.
  6. Check Developer Guide to edit a DOCX file in C#.

Support and Learning Resources