Hi,
I read that your Java libraries and other products have a License.isLicenseSet(); method and was just wondering if .NET has any similar method.
Also, when calling a license, can I call it after defining a document object but leaving it as null (not set to anything)?
Thanks,
Adam
Hi Adam,
Thanks for your inquiry.
I am afraid, the License class doesn’t expose any built-in methods to check/track the status whether a license is properly 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. Please see the following code:
///
/// Returns true if the Aspose.Words license is set.
///
private static bool IsLicenseSet()
{
// We will insert this text at the beggining of the document.
// If the license set this text will be in th efirt 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.ToTxt().Trim() == text);
}
Secondly, please make sure SetLicense
is executed before you instantiate any Document object. The following code would work fine though:
Aspose.Words.License license = new Aspose.Words.License();
Document doc = null;
license.SetLicense("Aspose.Words.lic");
doc = new Document();
doc.Save("out.docx");