title: Accessing Sitecore API from a CLI tool
body: <p>I would like to access the Sitecore API from within a command line tool (with a goal of exporting some information about users in the database), however I haven't been able to get a simple CLI program connected.</p>
  
  <p>To give a simple example</p>
  
  <pre><code>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());
      }
  </code></pre>
  
  <p>As this currently stands, I get the following exception</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>I assume this related to the inability of the system to find the appropriate web.config file (unsurprising since I never told it where it was), however I see no way of configuring this to tell it where to look.</p>
  
  <p>So, how can I configure Sitecore to find it's web.config file, or, how should I be approaching this problem differently to get access to the Sitecore API from a command line tool?</p>