gpt4 book ai didi

c# - 尝试以编程方式发布媒体项目时 PublishOptions 失败

转载 作者:行者123 更新时间:2023-11-30 14:57:57 25 4
gpt4 key购买 nike

我正在尝试以编程方式发布媒体项目,但我遇到了 PublishOptions 对象的问题。在运行时,当我上传媒体项目时,实例化 PublishOptions 对象的代码行被中断。我收到以下消息:

"Value cannot be null. Parameter Name: item"

堆栈跟踪是:

at Sitecore.Diagnostics.Assert.ArgumentNotNull(Object argument, String argumentName)
at Sitecore.Data.Managers.ItemProvider.ApplySecurity(Item item, SecurityCheck securityCheck)
at Sitecore.Data.Managers.ItemProvider.GetRootItem(Language language, Version version, Database database, SecurityCheck securityCheck)
at Sitecore.Data.Managers.ItemManager.GetRootItem(Language language, Version version, Database database)
at Sitecore.Nexus.Data.DataCommands.ResolvePathCommand.(String itemPath, Database database)
at Sitecore.Nexus.Data.DataCommands.ResolvePathCommand.(String itemPath, Database database)
at Sitecore.Nexus.Data.NexusDataApi.ResolvePath(String itemPath, Database database)
at Sitecore.Data.Engines.DataCommands.ResolvePathCommand.DoExecute()
at Sitecore.Data.Engines.EngineCommand`2.Execute()
at Sitecore.Data.Engines.DataEngine.ResolvePath(String itemPath)
at Sitecore.Data.Managers.ItemProvider.ResolvePath(String itemPath, Database database)
at Sitecore.Data.Managers.ItemProvider.GetItem(String itemPath, Language language, Version version, Database database, SecurityCheck

下面是实例化 PublishOptions 对象的代码(中断的地方):

public void OnItemSaved(Object sender, EventArgs args)
{
var item = Event.ExtractParameter(args, 0) as Item;

using (new SecurityDisabler())
{
if (item != null)
{
if (item.Paths.IsMediaItem)
{
var source = new Database("master");
var target = new Database("web");


var options = new PublishOptions(source, target, PublishMode.SingleItem, item.Language, DateTime.Now)
{
RootItem = item,
Deep = true,

};

var publisher = new Publisher(options);

publisher.PublishAsync();
}
}
}
}

我收到此错误的原因可能是什么?

最佳答案

试试这个,看看它是否有效,我猜它与数据库有关。

public void OnItemSaved(Object sender, EventArgs args)
{
var item = Event.ExtractParameter(args, 0) as Item;

using (new SecurityDisabler())
{
if (item != null)
{
if (item.Paths.IsMediaItem)
{
var source = Factory.GetDatabase("master");
var target = Factory.GetDatabase("web");

var options = new PublishOptions(source, target,
PublishMode.SingleItem, item.Language,
DateTime.Now)
{
RootItem = item,
Deep = true,
};

var publisher = new Publisher(options);

publisher.PublishAsync();
}
}
}
}

关于c# - 尝试以编程方式发布媒体项目时 PublishOptions 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19958800/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com