Introduction to the Laserfiche SDK

Contributed by:Joanna Slusarz, Technical Writer, Laserfiche

The Laserfiche SDK is a powerful software development toolkit that allows you to extend your enterprise content management capabilities with the creation of custom solutions. It is the same programming interface that Laserfiche developers use to develop all client-facing applications. Here are some ways to use the Laserfiche SDK.

SDK libraries

The Laserfiche SDK comes with different library types to choose from.

Laserfiche Server Objects (LFSO) – allows you to do everything that the Laserfiche Client and Administration Console can do when communicating with the Laserfiche Server.

  • Example: If you need to create a script that automatically updates the metadata on a series of documents, you can use LFSO.

Document Processor – deals with importing/exporting documents, converting image formats and OCRing text.

  • Example: If you are writing a utility that a user can run in order to import a batch of documents into the Laserfiche repository, you can use Document Processor.

Image Enable – allows third-party applications to manipulate the Laserfiche Client.

  • Example: If you would like to display invoices in the Laserfiche Client corresponding to a particular Product Number from within your Accounting Application, you can use Image Enable.

.NET: Repository Access – enables third-party applications to communicate with the Laserfiche Server. It ships with an ADO.NET provider that allows the repository to be queried as a structured data source (more about this later on in this article).

  • Example: If you would like to run a script from within your Accounting System that automatically stamps invoices in Laserfiche with the “Approved” stamp, you can use Repository Access.

.NET: Document Services – provides services for importing, exporting, OCRing and other operations related to Laserfiche repositories.

  • Example: If you are writing a utility for importing documents into Laserfiche you can use Document Services.

PDF Exporter – allows conversion of Tiff images to PDF documents during export from Laserfiche.

  • Example: If you are writing a script to export Tiff images and convert them to password-protected PDFs you can use PDF Exporter.

Java Repository Access (JRA) – mostly for document management with no admin functionality as of yet.

Use each of the libraries in the following situations:

  • LFSO/Document Processor libraries- If you are already familiar with LFSO or are using unmanaged code.
  • .NET libraries- If you are new to the Laserfiche SDK, as these are more condensed than the LFSO/Document Processor libraries.
  • JRA libraries- If you are used to working with Java.

Detailed information about each of the libraries along with code examples can be found in the Laserfiche SDK help files that come with your Laserfiche SDK installation.

SDK must-do’s

Once you’ve decided which libraries to use, make sure to follow these six steps for creating a robust Laserfiche SDK project:

  1. Create a connection to the Laserfiche Server or share an existing connection.
  2. Lock the documents before working on them in order to prevent other users from modifying them at the same time. Locking the document first improves server performance by preventing a potential notification overhead that results from a document auto-locking.
  3. Perform the actions on the documents.
  4. Save the changes.
  5. Release the locks on the documents.
  6. Release the connection.

Laserfiche Query Language (LFQL)

You can use the Laserfiche SDK to query the Laserfiche repository with Advanced Search Syntax (described thoroughly here) or LFQL – an internal custom Laserfiche query language with a structure and functionality similar to SQL. The results returned by the LFQL queries can then be used in your integrations or workflows.

The Laserfiche virtual tables, which define the range of information that you can query, are a major component of the LFQL. Each repository has its own set of virtual tables structured like relational database tables.

Example:

You would like to retrieve a list of entries that have the “Purchase_Order” template assigned to them which were modified after they were created. The following LFQL query returns the name, entry ID, created and modified dates of each of those entries.

Code Section

SELECT entry_name, entry_id, created_date, last_modified from lf.entry  WHERE pset_name = 'Purchase_Order' AND  last_modified >  created_date

Here is this query in the context of a C# code sample using Repository Access.

Code Section

LfConnection conn = new LfConnection(mySess);
conn.Open();
LfCommand lfqlCommand = conn.CreateCommand();
// Find all entries that are assigned the General template.
lfqlCommand.CommandText = "SELECT entry_name, entry_id, created_date, last_modified from lf.entry  WHERE pset_name = 'Purchase_Order' AND  last_modified >  created_date";
Laserfiche.RepositoryAccess.Data.LfDataReader reader = lfqlCommand.ExecuteReader();
if (reader.HasRows) // non-zero result set
{
while (reader.Read())
{
System.Windows.Forms.MessageBox.Show("Entry Name:" + reader["entry_name"].ToString() + " | Entry ID:" + reader["entry_id"].ToString());
}
}

Detailed LFQL syntax can be found here and in the “Laserfiche Query Language” whitepaper.

Note: if you are using Laserfiche Server 8.0/8.1, the LFCR_PRIV_READ_ACCESS privilege or the LFCR_PRIV_BYPASS_FILTER privilege is necessary to execute any LFQL query.

Language Integrated Query (LINQ)

LINQ is a Microsoft technology that essentially establishes a single, universal language to query data, no matter what the data source is.

  • The Repository Access LINQ provider generates LFQL queries from LINQ expressions and executes them using the Laserfiche ADO.NET provider.
  • These type of queries are easier to put together than LFQL queries, as they require less knowledge of the specific syntax, and your integrated development environment (such as Microsoft Visual Studio) can help you build them.

Here is an example of an LFQL query written using C#:

Code Section

RepositoryContext context = new RepositoryContext(mySess);
            IEnumerable res = from pages in context.Pages
                                         where pages.HasText == false
                                         select pages;
foreach (PageRow row in res)
            {
var id = row.EntryId;
                var pg = row.PageNumber;
                DoSomething(id, pg);
}
context.Dispose();

Detailed LINQ syntax can be found in the Laserfiche SDK help files that come with your Laserfiche SDK installation.