This tutorial shows how to use the LEADTOOLS SDK in a C# .NET Framework application and create a project, add references, and set the license.
Overview | |
---|---|
Summary | This tutorial covers how to set a license in a C# .NET Framework application. |
Completion Time | 30 minutes |
Visual Studio Project | Download tutorial project (2 KB) |
Platform | Windows C# Console Application |
IDE | Visual Studio 2017, 2019 |
Runtime License | Download LEADTOOLS |
Launch Visual Studio and select Create a new project, then click Next.
Select the C# Console .NET Framework application and then click Next.
Add the project's name, the location where the project will be saved, and the other project details, then click OK.
Add the necessary LEADTOOLS references. The references needed depend upon the purpose of the project. References can be added by one or the other of the following two methods (but not both).
Right-click the C# project in the Solution Explorer and select Manage NuGet Packages...
Browse for LEADTOOLS, then select one of the LEADTOOLS NuGet packages (any one will do) and install it. Accept LEAD's End User License Agreement.
To add the LEADTOOLS references locally, perform the following steps:
In the Solution Explorer right-click References, and select Add Reference.
In the Reference Manager, select Browse and then navigate to the directory where the LEADTOOLS Assemblies are located: C:\LEADTOOLS 20\Bin\Dotnet4\x64
Select and add Leadtools.dll
, then click OK.
Now that the LEADTOOLS references have been added to the project, code can be added to set the runtime license. The License unlocks the features needed for the project. It must be set before any toolkit function is called. The exact function called depends on the platform used. For details (including tutorials for different platforms), refer to Setting a Runtime License.
There are two types of runtime licenses:
Perform the following steps to add the SetLicense()
code:
In the Solution Explorer, open Program.cs
and add a using Leadtools;
to the using
block at the top.
In the Program
class add a new method called SetLicense()
and call it in the Main
method.
using System;
using System.IO;
using Leadtools;
namespace set_license_tutorial
{
class Program
{
static void Main(string[] args)
{
SetLicense();
}
static void SetLicense()
{
string license = @"C:\LEADTOOLS 20\Support\Common\License\LEADTOOLS.LIC";
string key = File.ReadAllText(@"C:\LEADTOOLS 20\Support\Common\License\LEADTOOLS.LIC.KEY");
RasterSupport.SetLicense(license, key);
if (RasterSupport.KernelExpired)
Console.WriteLine("License file invalid or expired.");
else
Console.WriteLine("License file set successfully");
}
}
}
Run the project by pressing F5 or by selecting Debug -> Start Debugging.
If the steps were followed correctly, a message in the console displays License file set successfully
.
This tutorial showed how to create a new C# .NET Framework Project, add references via NuGet or via local LEADTOOLS DLLs, and set the license.
This is the basis for all C# .NET Framework applications using the LEADTOOLS SDK. All functionality in the SDK is unlocked via setting a license. SetLicense
must be called before calling any other LEADTOOLS SDK methods.
After the SDK is purchased, the evaluation license can be replaced with a valid runtime license to disable the Nag Message.