Accessing Sitecore APIs from the CLI Tool

I would like to access the Sitecore API from the command line tool (in order to export some information about users in the database), however I was not able to connect a simple CLI program.

To give a simple example

using Sitecore; using Sitecore.Configuration; using Sitecore.Data; using Sitecore.Data.Items; ... static void Main(string[] args) { Sitecore.Data.Database master = Sitecore.Configuration.Factory.GetDatabase("master"); Console.WriteLine(master.Items.ToString()); } 

I am currently getting the following exception

 Unhandled Exception: System.InvalidOperationException: Could not read Sitecore configuration. at Sitecore.Configuration.Factory.GetConfiguration() at Sitecore.Configuration.Factory.GetConfigNode(String xpath, Boolean assert) at Sitecore.Configuration.Factory.CreateObject(String configPath, String[] parameters, Boolean assert) at Sitecore.Configuration.Factory.CreateObject(String configPath, Boolean assert) at Sitecore.Configuration.Factory.GetDatabase(String name, Boolean assert) at Sitecore.Configuration.Factory.GetDatabase(String name) at Example.Program.Main(String[] args) 

I assume that this is due to the inability of the system to find the corresponding web.config file (not surprising, since I never said where it was), but I see no way to configure this to tell where to look.

So, how can I configure Sitecore to find its web.config file, or how should I approach this problem differently in order to access the Sitecore API from the command line tool?

+4
source share
1 answer

This may be possible using App.Config (I cannot confirm or deny), but it will be much easier for you to do this through a web service. Most likely, the easiest way is to create a custom web service with the necessary logic and use the CLI to call / start the service.

+3
source

All Articles