问题描述
我有一个应用程序,该应用程序正在Sitecore中创建一个新项目,然后将内容编辑器打开到该项目,它的加载很好,但是每当我尝试打开html编辑器时,我都会收到"NullReferenceException".只有当我以这种方法启动应用程序时,这种情况才会发生.
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.
源代码:
[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());
}
在加载这两种方法时,我唯一可以看出的区别是html编辑器的url,但是我不知道它的定义位置或控制方式.
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.
通过常规方法启动: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 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
通过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
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.
推荐答案
Phil,
如果答案还为时不晚... :)您可能在没有读取核心数据库的权限的情况下运行此代码.在这种情况下,当您尝试调用contentEditor时.您将获得NullReference.我建议您使用另一种运行应用程序的格式-使用另一种方法:
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.
希望这会有所帮助.
这篇关于从代码启动内容编辑器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!