The user document associated with this document.
public string UserToken {get; set;} public:property String^ UserToken{String^ get()void set(String^ value)}
UserToken # get and set (DocumentCacheInfo)
The user token associated with this document. The default value is null.
Note that the current behavior of the toolkit is to clear this value for security reasons when DocumentFactory.GetDocumentCacheInfo is called, and will be null regardless of the value in the cache.
HasUserToken can be used to determine if the document was created with a user token. When a document is loaded successfully, the user token value will be set in the LEADDocument.UserToken property.
Refer to Loading Using LEADTOOLS Document Library for more information.
using Leadtools;using Leadtools.Codecs;using Leadtools.Document.Writer;using Leadtools.Document;using Leadtools.Caching;using Leadtools.Annotations.Engine;using Leadtools.Ocr;using Leadtools.Barcode;using Leadtools.Document.Converter;public void UserTokenExample(){var cache = GetCache();var documentUri = new Uri("https://demo.leadtools.com/images/pdf/leadtools.pdf");const string documentId = "document-with-token";const string userToken = "my-secret";// Load from the URI without a tokenvar loadDocumentOptions = new LoadDocumentOptions();loadDocumentOptions.Cache = cache;loadDocumentOptions.DocumentId = documentId;Console.WriteLine("Loading a document into the cache without a user token");using (var document = DocumentFactory.LoadFromUri(documentUri, loadDocumentOptions)){// Make sure it does not have a user tokenAssert.IsNull(document.UserToken);document.AutoSaveToCache = false;document.AutoDeleteFromCache = false;document.SaveToCache();}// Load from cachevar loadFromCacheOptions = new LoadFromCacheOptions();loadFromCacheOptions.Cache = cache;loadFromCacheOptions.DocumentId = documentId;loadFromCacheOptions.UserToken = null;// This should workConsole.WriteLine("Loading the document from the cache without a user token");using (var document = DocumentFactory.LoadFromCache(loadFromCacheOptions)){// Make sure it does not have a user tokenAssert.IsNotNull(document);}// Load it again and set the tokenConsole.WriteLine("Setting the document user token and saving it into the cache");using (var document = DocumentFactory.LoadFromCache(loadFromCacheOptions)){// Make sure it does not have a user tokenAssert.IsNull(document.UserToken);// Set a tokendocument.UserToken = userToken;document.SaveToCache();}// This should failConsole.WriteLine("Loading the document without a user token");using (var document = DocumentFactory.LoadFromCache(loadFromCacheOptions)){// Make sure it did not loadAssert.IsNull(document);}// This should workloadFromCacheOptions.UserToken = userToken;Console.WriteLine("Loading the document with a user token");using (var document = DocumentFactory.LoadFromCache(loadFromCacheOptions)){// Make sure it has the same user tokenAssert.IsNotNull(document);Assert.AreEqual(userToken, document.UserToken);}// This should failloadFromCacheOptions.UserToken = null;Console.WriteLine("Deleting the document without a user token");bool isDeletedFromCache = DocumentFactory.DeleteFromCache(loadFromCacheOptions);// Make sure it did not get deletedAssert.IsFalse(isDeletedFromCache);// This should workloadFromCacheOptions.UserToken = userToken;Console.WriteLine("Deleting the document with a user token");isDeletedFromCache = DocumentFactory.DeleteFromCache(loadFromCacheOptions);// Make sure it got deletedAssert.IsTrue(isDeletedFromCache);}public ObjectCache GetCache(){// Create a LEADTOOLS FileCache objectvar cacheDir = Path.Combine(LEAD_VARS.ImagesDir, "cache");if (Directory.Exists(cacheDir))Directory.Delete(cacheDir, true);Directory.CreateDirectory(cacheDir);var cache = new FileCache();cache.CacheDirectory = cacheDir;return cache;}static class LEAD_VARS{public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images";}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
