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?
source share