Accessing Sitecore API from a CLI tool

风格不统一 提交于 2019-12-04 13:32:39

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/6621083/accessing-sitecore-api-from-a-cli-tool

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!