License Validation | C# Code to Check if License of Aspose.Words for .NET API has already been Set/Applied

Hi,


Is it possible to add license validation method?
similar to what the pdf or the excel products have

Hi Dvir,

Thanks for your inquiry.

There is no built-in method to check whether the license is already applied or not. However, if you want to be sure, you can try creating your own custom method to do this job. To do this you could create a blank document and export this to a stream. Then reload this and check the first paragraph in the body for the evaluation message.

///
/// Returns true if the Aspose.Words license is set.
///
private static bool IsLicenseSet()
{
    // We will insert this text at the begining of the document.
    // If the license is set then this text will be in the first paragraph,
    // if not an evaluation watermark will be in the first paragraph.
    const string text = "This is text used to check if the license is set";

    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);
    builder.Write(text);

    // Save and open the document. If Aspose.Words works in evaluation mode it will add a watermark.
    using (MemoryStream docStream = new MemoryStream())
    {
        doc.Save(docStream, SaveFormat.Doc);
        docStream.Position = 0;
        doc = new Document(docStream);
    }

    // Check text of the first paragraph.
    return (doc.FirstSection.Body.FirstParagraph.ToString(SaveFormat.Text).Trim() == text);
}