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

How to: Attach a File to a Document

  • 2 minutes to read

Important

You need a license for the DevExpress Office File API Subscription or DevExpress Universal Subscription to use these examples in production code.

This example shows how to programmatically attach a file to the PDF document.

To do this:

using DevExpress.Pdf;
using System;
using System.IO;

namespace AttachFile {
    class Program {
        static void Main(string[] args) {

            using (PdfDocumentProcessor processor = new PdfDocumentProcessor()) {
                // Load a document.
                processor.LoadDocument("..\\..\\Document.pdf");

                // Attach a file to the PDF document. 
                processor.AttachFile(new PdfFileAttachment() {
                    CreationDate = DateTime.Now,
                    Description = "This is my attach file.",
                    FileName = "MyAttach.txt",
                    Data = File.ReadAllBytes("..\\..\\FileToAttach.txt")
                });

                // The attached document.
                processor.SaveDocument("..\\..\\Result.pdf");
            }
        }
    }
}
See Also