using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Laserfiche.DocumentServices; using Laserfiche.RepositoryAccess; using System.Windows; namespace ImportDocument { class Program { static void Main(string[] args) { #region Log in and create session RepositoryRegistration repoReg = new RepositoryRegistration("localhost", "LaserInvestigators"); Session session = new Session(); session.LogIn(repoReg); #endregion //System.Console.WriteLine("Creating a new document in Laserfiche in the TEST folder.") try { DocumentImporter Importer = new DocumentImporter(); /** * We're doing this next part to explore a common technique, but note that this line... * FolderInfo parentFolder = Folder.GetFolderInfo(Folder.Create("\\Test", "DEFAULT", EntryNameOption.None, session), session); * ...will throw exceptions to let you know what's going on. **/ // Does my parent folder exist? If not, let's make it! FolderInfo parentFolder; SearchResultListing searchResults; using (Search lfSearch = new Search(session, "{LF:Name=\"TEST\", Type=\"F\"} & {LF:LOOKIN=\"LaserInvestigators\\\"}")) { lfSearch.BeginRun(true); SearchListingSettings searchSettings = new SearchListingSettings(); searchResults = lfSearch.GetResultListing(searchSettings); } System.Console.WriteLine("Search Results: " + searchResults.RowCount); if (searchResults.RowCount == 0) { parentFolder = Folder.GetFolderInfo(Folder.Create("\\TEST", "DEFAULT", EntryNameOption.AutoRename, session), session); System.Console.WriteLine("Folder created successfully!"); } else { parentFolder = Folder.GetFolderInfo((int)searchResults.GetDatum(1, SystemColumn.Id), session); System.Console.WriteLine("Found the TEST folder and will use it."); } // Create the entry to import into and lock the document DocumentInfo newDoc = Document.GetDocumentInfo( Document.Create(parentFolder, "My Document", EntryNameOption.AutoRename, session), session); newDoc.Lock(LockType.Exclusive); // Template and Fields System.Console.WriteLine("More fields... MORE FIELDS!"); newDoc.SetTemplate("Case Files"); FieldValueCollection fieldValues = newDoc.GetFieldValues(); fieldValues["Case ID"] = 12345; fieldValues["Investigator Assigned"] = "Sly Boots"; //fieldValues["Date"] = "cat!"; fieldValues["Date"] = System.DateTime.Today; newDoc.SetFieldValues(fieldValues); // Versioning System.Console.WriteLine("Versioning, activate!"); newDoc.PutUnderVersionControl(); // Images (Accepts both a file stream or a file. Can specify particular pages if wanted.) System.Console.WriteLine("Pages... assemble!"); Importer.Document = newDoc; Importer.ImportImages(@"C:\Program Files (x86)\Laserfiche\Client\SAMPLE 2.tif"); // OCR System.Console.WriteLine("Someone set up us the OCR!"); OcrEngine myOcr = OcrEngine.LoadEngine(); myOcr.AutoOrient = true; myOcr.Decolumnize = false; myOcr.Language = "English"; myOcr.OptimizationMode = OcrOptimizationMode.Accuracy; myOcr.Run(newDoc); // Save changes and release the document. newDoc.Save(); newDoc.Unlock(); } catch (Exception ex) { System.Console.WriteLine(ex.Message); } System.Console.WriteLine("Press return to exit..."); System.Console.ReadLine(); session.Close(); } } }