Hello Alexey, here is the code from my Program.cs file:
namespace SigningTool
{
internal static class Program
{
[STAThread]
static void Main()
//static void Main(string[] args)
{
loaded from a single-file bundle
FileInfo errorlicensefile;
string xUSERNAME = Environment.UserName; //only UserName, without Domain
errorlicensefile = new FileInfo("C:\\Users\\" + xUSERNAME + "\\AppData\\Roaming\\Error_Loading_Licenses.txt");
string xerrorfile = errorlicensefile.FullName;
if (!File.Exists(errorlicensefile.FullName))
{
var myFile = File.Create(errorlicensefile.FullName);
myFile.Close();
}
// File.WriteAllText(errorlicensefile.FullName, "------------------------------------------------");
// #################################################################################################
// Loading Aspose licenses
// #################################################################################################
string message = " ";
string title = " ";
//var resourceNames = Assembly.GetExecutingAssembly().GetManifestResourceNames();
//foreach (var name in resourceNames)
//{
// // Console.WriteLine(name);
// message = "Resourcename: " + name + "\r\n\r\n" + message;
// MessageBox.Show(message, title, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
//}
Aspose.Words.License licenseWord = new Aspose.Words.License();
// Method A (does not work)
// Load license information from embedded resources.
// After a possible exchange of the file under Resources, it must be set to embedded and not copy.
//string resourceName = "Aspose.Words.NET.lic";
//using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
//{
// if (stream != null)
// {
// licenseWord.SetLicense(stream);
// message = "Aspose.Words .Net is licensed";
// // Console.WriteLine(message);
// }
// else
// {
// message = "Aspose.Words .Net is NOT licensed";
// // Console.WriteLine(message);
// }
// MessageBox.Show(message, title, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
//}
// Method B
// Load license information from embedded resources.
// After a possible exchange of the file under Resources, it must be set to embedded and not copy.
try
{
licenseWord.SetLicense("SigningTool.Resources.Aspose.Words.NET.lic");
// message = "Aspose.Words .Net is licensed";
// MessageBox.Show(message, title, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
}
catch (Exception ex)
{
message = "Aspose.Words .Net is NOT licensed.\r\n\r\nThe error message is saved in the following file:\r\n\r\n" + errorlicensefile + "\r\n\r\n" + ex;
File.WriteAllText(errorlicensefile.FullName, message);
MessageBox.Show(message, title, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
}
// Method C
// Alternative variant for the test phase, which loads the license file from the local directory.
// Do not use for productive license.
//try
//{
// string licenseFileNameWord = Path.Combine("C:\\Program Files\\SigningTool\\li\\", "Aspose.Words.NET.lic");
// licenseWord.SetLicense(licenseFileNameWord);
// message = "Aspose.Words .Net is licensed";
// MessageBox.Show(message, title, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
//}
//catch (Exception ex)
//{
// message = "Aspose.Words .Net is NOT licensed. Error Message:\r\n\r\n" + ex;
// MessageBox.Show(message, title, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
//}
// #################################################################################################
Aspose.Cells.License licenseCells = new Aspose.Cells.License();
// Method A (does not work)
// Load license information from embedded resources.
// After a possible exchange of the file under Resources, it must be set to embedded and not copy.
//string resourceName = "Aspose.Cells.NET.lic";
//using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
//{
// if (stream != null)
// {
// licenseCells.SetLicense(stream);
// message = "Aspose.Cells .Net is licensed";
// // Console.WriteLine(message);
// }
// else
// {
// message = "Aspose.Cells .Net is NOT licensed";
// // Console.WriteLine(message);
// }
// MessageBox.Show(message, title, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
//}
// Method B
// Load license information from embedded resources.
// After a possible exchange of the file under Resources, it must be set to embedded and not copy.
try
{
licenseCells.SetLicense("SigningTool.Resources.Aspose.Cells.NET.lic");
// message = "Aspose.Cells .Net is licensed";
// MessageBox.Show(message, title, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
}
catch (Exception ex)
{
message = "Aspose.Cells .Net is NOT licensed.\r\n\r\nThe error message is saved in the following file:\r\n\r\n" + errorlicensefile + "\r\n\r\n" + ex;
File.WriteAllText(errorlicensefile.FullName, message);
MessageBox.Show(message, title, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
}
// Another method to check if it's licensed.
//Workbook workbook = new Workbook();
//Console.WriteLine("Aspose.Cells licensed: " + workbook.IsLicensed);
//if (workbook.IsLicensed)
//{
// message = "Aspose.Cells is licensed";
//}
//else
//{
// message = "Aspose.Cells is NOT licensed";
//}
//MessageBox.Show(message, title, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
// #################################################################################################
// #################################################################################################
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
}
}
}