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

Getting Started

  • 2 minutes to read

This tutorial describes how to get started with the non-visual RichEditDocumentServer component.

  1. Start Visual Studio and create a new project by selecting FILE | New | Project… in the main menu. In the invoked New Project dialog, select Console Application, specify the project name and location, and click OK.

    RichEditDocServer_GettingStarted_CreateNewProject

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

    RichEditDocServer_GettingStarted_AddReference

  3. In the invoked Reference Manager dialog, add references to the following libraries.

    • DevExpress.Data.v17.2.dll
    • DevExpress.Office.v17.2.Core.dll
    • DevExpress.RichEdit.v17.2.Core.dll
    • DevExpress.Printing.v17.2.Core.dll

    Note

    To follow this example, you should also include a reference to the System.Drawing.dll library, since the code example below uses the Color.FromArgb method to set the font color of the specified text.

  4. 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 RichEditDocumentServerTest.docx file, and opens it in the default application registered for this file type.

    using DevExpress.XtraRichEdit;
    using DevExpress.XtraRichEdit.API.Native;
    using System.Drawing;
    // ...
    
    string fileName = "RichEditDocumentServerTest.docx";
    using (RichEditDocumentServer srv = new RichEditDocumentServer())
    {
        Document doc = srv.Document;
        doc.AppendText("This document is generated by the RichEdit Document Server");
        CharacterProperties cp = doc.BeginUpdateCharacters(doc.Paragraphs[0].Range);
        cp.ForeColor = Color.FromArgb(0x83, 0x92, 0x96);
        cp.Italic = true;
        doc.EndUpdateCharacters(cp);
        ParagraphProperties pp = doc.BeginUpdateParagraphs(doc.Paragraphs[0].Range);
        pp.Alignment = ParagraphAlignment.Right;
        doc.EndUpdateParagraphs(pp);
        srv.SaveDocument(fileName, DocumentFormat.OpenXml);
    }
    System.Diagnostics.Process.Start(fileName);
    
  5. Run the project.

The following image demonstrates the file generated after executing the code above (the document is opened in Microsoft® Word®).

RichEditDocServer_GettingStarted_Result