Launch Content Editor from code

血红的双手。 提交于 2020-01-24 13:45:03

问题


I have an application that is creating an new item in Sitecore then opening up the Content Editor to that item, it is loading fine but whenever i try to open the html editor i get a 'NullReferenceException'. This is only happening when i launch the application in this method.

Source Code:

[Serializable]
public class PushToCMS : Command
{
    public override void Execute(CommandContext context)
    {
        //Context.ClientPage.Start(this, "Action_PushToCMS");

        Database dbCore = Sitecore.Configuration.Factory.GetDatabase("core");
        Item contentEditor = dbCore.GetItem(new ID("{7EADA46B-11E2-4EC1-8C44-BE75784FF105}"));

        Database dbMaster = Sitecore.Configuration.Factory.GetDatabase("master");
        DatabaseEngines engine = new DatabaseEngines(dbMaster);

        Item parentItem = dbMaster.GetItem("/sitecore/content/Home/Events/Parent/");

        // Load existing related item if it exists
        Event evt = new Event(new Guid(HttpContext.Current.Items["id"].ToString()));
        Item item = dbMaster.SelectSingleItem("/sitecore/content/Home/Events/Parent/Item");

        if (item == null)
            item = CreateNewEvent(engine.DataEngine, parentItem, evt);

        Sitecore.Text.UrlString parameters = new Sitecore.Text.UrlString();
        parameters.Add("id", item.ID.ToString());
        parameters.Add("fo", item.ID.ToString());
        Sitecore.Shell.Framework.Windows.RunApplication(contentEditor, contentEditor.Appearance.Icon, contentEditor.DisplayName, parameters.ToString());
    }

The only difference i can tell in the loading of the two methods is the url to the html editor, however i dont know where this is being defined or how i can control it.

Launched through normal method: http://xxxx/sitecore/shell/default.aspx?xmlcontrol=RichTextEditor&da=core&id=%7bDD4372AC-5D37-4C9E-BBFA-C4E3E2A27722%7d&ed=F27055570&vs&la=en&fld=%7b60D10DBB-7CD5-4341-A960-C7AB10347A2C%7d&so&di=0&hdl=H27055699&us=%7b83D34C8A-4CC4-4CD9-A209-600D51B26AAE%7d&mo

Launched through RunApplication: http://xxxx/layouts/xmlcontrol.aspx?xmlcontrol=RichTextEditor&da=core&id=%7bDD4372AC-5D37-4C9E-BBFA-C4E3E2A27722%7d&ed=F27055196&vs&la=en&fld=%7b60D10DBB-7CD5-4341-A960-C7AB10347A2C%7d&so&di=0&hdl=H27055325&us=%7b83D34C8A-4CC4-4CD9-A209-600D51B26AAE%7d&mo

any help on this would be greatly appreciated.


回答1:


Phil,

If it is not too late for the answer... :) It might be the case that you run this code without the permissions to read the core database. In this case, when you try to call contentEditor. you'll get NullReference. I would recommend you using another format of running the application - use another method:

Sitecore.Shell.Framework.Windows.RunApplication("Content Editor", parameters.ToString());

If this doesn't help, please attach the stack trace of the exception you get.

Hope this helps.



来源:https://stackoverflow.com/questions/161007/launch-content-editor-from-code

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