How to create a console application

From Sense/Net Wiki
Jump to: navigation, search
  • 100%
  • 6.0
  • Enterprise
  • Community
  • Planned


Sense/Net ECMS is a carefully layered system that can serve enterprise needs from ground (storing data) to the top (publishing and displaying). If you want to access only the Content Repository layer from outside the portal, it can be done by creating a custom application (any kind of .NET application: console, desktop or web application, etc.). This means that you can leverage the high performance and the capabilities of our data storage and querying in any application, be it ASP.NET or a nonweb environment such as a Windows application or console application, Windows service, etc.

This is usefull for the following development scenarios:

  • First time users: experiment and play with the Sense/Net Content Repository in a console application to get immediate results
  • Use Sense/Net Content Repository as a general purpose content repository regardless of application type
  • Create data storage agnostic, business entity oriented applications
  • Creating tools or other applications which connect to the Content Repository of an existing Sense/Net installation


Configure the Content Repository

  • In your application add a reference to the following Sense/Net libraries:
    • SenseNet.ContentRepository.dll
    • SenseNet.Storage.dll
    • SenseNet.Portal.dll
  • Set some application config settings in your .config file (the same configuration settings that are used in the Web.config file of Sense/Net apply here)
    <add name="SnCrMsSql" connectionString="Server=vbox-sensenet\sqlexpress;Database=SNCR;uid=sncruser;Pwd=******;" providerName="System.Data.SqlClient" />
    <add key="DataProvider" value="SenseNet.ContentRepository.Storage.Data.SqlClient.SqlProvider" />
    <add key="AccessProvider" value="SenseNet.ContentRepository.Security.UserAccessProvider" />
    <add key="DefaultLockTimeout" value="10000000" />
    <!-- Lucene specific configuration -->

Start and use the repository

In your code, you must start the Repository. This can be done with a static method and the returned result also implements IDisposable so you can use this together with the C# using statement to shut down the repository instance gracefully and free up the resources used by it.

You can supply a RepositoryStartSettings object to this method to set various features of the repository.

var startSettings = new RepositoryStartSettings
    Console = Console.Out,
    StartLuceneManager = StorageContext.Search.IsOuterEngineEnabled,
    PluginsPath = AppDomain.CurrentDomain.BaseDirectory
using (Repository.Start(startSettings))
    //use the Content Repository here: load or save content, etc.

Please note that you may provide a custom plugins path when starting the Content Repository to point the system where your custom libraries are to allow the system to load them properly.

Inside the above using statement you can use features of the Repository, such as loading or saving content or just displaying information.

Folder rootNode = Node.Load<Folder>("/Root");
foreach (Node childNode in rootNode.Children)

Communication between applications

Note that if you use multiple processes to access the same Content Repository, you must also configure Communication between appdomains.

Usage in a web scenario

In a web scenario, you typically want to start one repository instance for the whole lifetime of your application. This can be achieved by just calling Repository.Start when the application starts and Repository.Stop when the application ends (without the using statement).

Related links


There are no related external articles for this article.