Hello, World!

Contents
[ ]

A “Hello, World!” code is often the first simple example to write uisng “Aspose.Words for .NET”, and it can also be used as a sanity test to ensure the software intended to compile or run source code is correctly installed.

“Aspose.Words for .NET” C# library gives developers direct access to create, modify, merge, convert, compare Word and Web documents. PDF, DOCX, DOC, RTF, ODT, EPUB, HTML and many other file formats are supported.

Below code snippet follows these steps:

  1. Create a new empty Document
  2. Initialize a DocumentBuilder class
  3. Insert text to the document start using simple Write method
  4. Open an existing Document from a file. Automatically detects the file format
  5. Append document “A” to the and of the document “B”
  6. Save the output as PDF

The following code snippet is a “Hello, World!” example to exhibit working of “Aspose.Words for .NET” API:


FAQ

  1. Q: How do I apply my Aspose.Words license to avoid evaluation restrictions?
    A: Download the license file (.lic) from your Aspose account and set it before using any API calls:

    License license = new License();
    license.SetLicense("Aspose.Words.lic");
    

    This must be done once per application start‑up; otherwise you will receive a “License not set” exception.

  2. Q: Which file formats can I save the document to directly from the Hello World example?
    A: The Document.Save method supports all formats listed on the Supported Document Formats page, including PDF, DOCX, DOC, RTF, ODT, EPUB, HTML, and more. Specify the desired format by using the appropriate file extension, e.g., document.Save("output.pdf");.

  3. Q: How can I convert the created document to PDF without changing the code that writes the text?
    A: After building the document, simply call Save with a .pdf extension:

    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);
    builder.Write("Hello, World!");
    doc.Save("HelloWorld.pdf");
    

    Aspose.Words automatically performs the conversion.

  4. Q: Why do I get a “File not found” error when the example tries to open an existing document?
    A: The Document constructor expects a valid path. Ensure the file exists relative to the application’s working directory or provide an absolute path. You can also verify the path with System.IO.File.Exists(path) before loading. If the file is embedded as a resource, load it via a stream instead of a file path.