This guide explains how to create a program that uses DsWord to generate and save to disk a DOCX file with the "Hello, World!" text.

Document Solutions for Word assemblies are built for .NET Standard 2.0, and can be used with any target that supports it. In this short tutorial, we show how to build a .NET Core console application. The tutorial takes you through the steps required to do that in Visual Studio on Windows or MAC, or Visual Studio Code on Linux.

Create an empty console application

Using Visual Studio on Windows

  1. Open Visual Studio for Windows.
  2. Create a new .NET Core Console Application.
  3. Right click the project in Solution Explorer and choose Manage NuGet Packages.
  4. In Package source in top right, select nuget.org.
  5. Click Browse tab in top left and enter "DS.Documents" as the search string. You should see several DS.Documents packages listed.
  6. Select DS.Documents.Word and DS.Documents.Layout, and click Install. Accept the license agreement.

This will add the required references to your application. You can now jump to Adding Code topic below to modify the application so that it generates the DOCX.

Using Visual Studio on MAC

  1. Open Visual Studio for MAC.
  2. Create a new .NET Core Console Application.
  3. In the tree view on the left, right click Dependencies and choose Add Packages.
  4. In the Search panel, type "DS.Documents".
  5. From the list in the left panel, select DS.Documents.Word and DS.Documents.Layout, and click Add Packages.
  6. Accept the license agreement.

This will add the required references to your application. You can now jump to Adding Code topic below to modify the application so that it generates the DOCX.

Using Visual Studio Code on Linux

  1. In a terminal window (you may use the Terminal in Visual Studio Code), type the following commands:
$ mkdir ~/MyApp # create a directory for the application
$ cd ~/MyApp
$ dotnet new console # create a .NET Core application with MyApp.csproj and Program.cs files
  1. Open Visual Studio Code.
  2. If you haven't already done so, from Extensions install Nuget Package Manager, and activate it.
  3. In Visual Studio Code, press Ctrl+P to open the file command box, type > in it, find "Nuget Package Manager: Add Package" in the list that opens, and click it.
  4. In the search box that opens, type "DS.Documents" and press Enter. This should bring up the list of available DS.Documents packages.
  5. Select DS.Documents.Word and DS.Documents.Layout. This will add a reference to these packages to you .csproj file, which would now look like this:
<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>netcoreapp3.1</TargetFramework>
    </PropertyGroup>
    <ItemGroup>
        <PackageReference Include="DS.Documents.Word" Version="7.0.0" />
        <PackageReference Include="DS.Documents.Layout" Version="7.0.0" />
    </ItemGroup>
</Project>
  1. In a terminal window, type the following commands to build and run the app:
$ cd ~/MyApp
$ dotnet restore # fetches referenced packages for MyApp.csproj
$ dotnet run # runs the default app

At this point you should see the "Hello, World!" printed in the terminal window (the default behavior of a new console app). Now modify the application so that it generates the DOCX, and also exports it to PDF, instead.

Adding Code

Open Program.cs in Visual Studio or Visual Studio Code, and modify it so that it looks like this:
using System;
using System.Drawing;
using GrapeCity.Documents.Word;
using GrapeCity.Documents.Layout;
using GrapeCity.Documents.Text;

namespace MyApp
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a new Word document:
            GcWordDocument doc = new GcWordDocument();
            // Add a paragraph with the 'Hello, World!' text to the first section:
            doc.Body.Sections.First.GetRange().Paragraphs.Add("Hello, World!");
            // Save the DOCX:
            doc.Save("HelloWorld.docx");
            // Export DOCX to PDF:
            doc.SaveAsPdf("HelloWorld.pdf");
        }
    }
}
Now run the application:
$ cd ~/MyApp
$ dotnet run # runs MyApp

That's all it takes to generate a DOCX file using DsWord. The HelloWorld.docx and HelloWorld.pdf should now appear in your project directory.

Essentially the same program is implemented by the Hello, World! sample, so you can see it in action:

This concludes this short guide. For more information please see the About page and the Docs.