views:

254

answers:

1

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  A: 

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.

Yan Sklyarenko