Skip to main content
A newer version of this page is available. .

Get Started - Create a Word Document

  • 3 minutes to read

This tutorial describes how to get started with the Word Processing Document API for .NET Framework and .NET Core.

Create a .NET Framework Application

  1. Start Visual Studio and create a new Console Application (.NET Framework) project.

  2. In the Solution Explorer, right-click the References node and select Add Reference… in the context menu.

    RichEditDocServer_GettingStarted_AddReference

  3. Add references to the following libraries.

    • System.Drawing.dll (to follow this example only)
    • DevExpress.Data.v20.2.dll
    • DevExpress.Office.v20.2.Core.dll
    • DevExpress.RichEdit.v20.2.Core.dll
    • DevExpress.Printing.v20.2.Core.dll
    • DevExpress.Pdf.v20.2.Core.dll
  4. Paste the code from below in the Main method of the Program.cs file (or the Main procedure of the Module1.vb file for Visual Basic). This example creates and saves the Test.docx file, and opens it in the default application registered for this file type.
    static void Main(string[] args)
    {
        string fileName = "Test.docx";
        using (DevExpress.XtraRichEdit.RichEditDocumentServer srv = 
            new DevExpress.XtraRichEdit.RichEditDocumentServer())
        {
            DevExpress.XtraRichEdit.API.Native.Document doc = srv.Document;
            doc.AppendText("This document is generated by Word Processing Document API");
            DevExpress.XtraRichEdit.API.Native.CharacterProperties cp = doc.BeginUpdateCharacters(doc.Paragraphs[0].Range);
            cp.ForeColor = System.Drawing.Color.FromArgb(0x83, 0x92, 0x96);
            cp.Italic = true;
            doc.EndUpdateCharacters(cp);
            DevExpress.XtraRichEdit.API.Native.ParagraphProperties pp = doc.BeginUpdateParagraphs(doc.Paragraphs[0].Range);
            pp.Alignment = DevExpress.XtraRichEdit.API.Native.ParagraphAlignment.Right;
            doc.EndUpdateParagraphs(pp);
            srv.SaveDocument(fileName, DevExpress.XtraRichEdit.DocumentFormat.OpenXml);
        }
        System.Diagnostics.Process.Start(fileName);
    }
    
  5. Run the project. The generated file appears as follows (the document is opened in Microsoft® Word®).

    RichEditDocServer_GettingStarted_Result

Create a .NET Core Application

  1. Start Visual Studio and create a new Console Application (.NET Core) project.

  2. Install the DevExpress.Document.Processor or DevExpress.RichEdit.Core NuGet package.

    Important

    You need an active license for the DevExpress Office File API Subscription or DevExpress Universal Subscription to use the DevExpress.Document.Processor package in production code.

  3. Paste the code listed below in the Main method of the Program.cs file (or the Main procedure of the Module1.vb file for Visual Basic). This example creates and saves the Test.docx file, and opens it in the default application registered for this file type.

    static void Main(string[] args)
    {
        string fileName = "Test.docx";
        using (DevExpress.XtraRichEdit.RichEditDocumentServer srv =
            new DevExpress.XtraRichEdit.RichEditDocumentServer())
        {
            DevExpress.XtraRichEdit.API.Native.Document doc = srv.Document;
            doc.AppendText("This document is generated by Word Processing Document API");
            DevExpress.XtraRichEdit.API.Native.CharacterProperties cp = doc.BeginUpdateCharacters(doc.Paragraphs[0].Range);
            cp.ForeColor = System.Drawing.Color.FromArgb(0x83, 0x92, 0x96);
            cp.Italic = true;
            doc.EndUpdateCharacters(cp);
            DevExpress.XtraRichEdit.API.Native.ParagraphProperties pp = doc.BeginUpdateParagraphs(doc.Paragraphs[0].Range);
            pp.Alignment = DevExpress.XtraRichEdit.API.Native.ParagraphAlignment.Right;
            doc.EndUpdateParagraphs(pp);
            srv.SaveDocument(fileName, DevExpress.XtraRichEdit.DocumentFormat.OpenXml);
        }
        Process.Start(new ProcessStartInfo(fileName) { UseShellExecute = true });
    }
    
  4. Run the project. The generated file appears as follows (the document is opened in Microsoft® Word®).

    RichEditDocServer_GettingStarted_Result