Accessing Sitecore API from a CLI tool
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.
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());
}
As this currently stands, I get 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开发者_JAVA技巧 Sitecore.Configuration.Factory.GetDatabase(String name, Boolean assert)
at Sitecore.Configuration.Factory.GetDatabase(String name)
at Example.Program.Main(String[] args)
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.
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?
This may be possible using App.Config (I cannot confirm or deny) but you will have a much easier time doing this by web service. Likely easiest would be to create a custom web service with the logic you need, and use a CLI to call/trigger the service.
精彩评论