我找到了一些关于如何向页面添加块的建议,但无法按照我想要的方式工作,所以也许有人可以提供帮助。
我想要做的是安排一个读取文件的计划作业,创建具有特定页面类型的新页面,并在新页面中向内容属性添加一些块。块字段将使用读取的文件中的数据进行更新。
我在预定的作业中有以下代码,但它失败了
repo.Save((IContent) newBlock, SaveAction.Publish);
Run Code Online (Sandbox Code Playgroud)
给出错误
页面名称必须至少包含一个可见字符。
这是我的代码:
public override string Execute()
{
//Call OnStatusChanged to periodically notify progress of job for manually started jobs
OnStatusChanged(String.Format("Starting execution of {0}", this.GetType()));
//Create Person page
PageReference parent = PageReference.StartPage;
//IContentRepository contentRepository = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<IContentRepository>();
//IContentTypeRepository contentTypeRepository = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<IContentTypeRepository>();
//var repository = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<IContentRepository>();
//var slaegtPage = repository.GetDefault<SlaegtPage>(ContentReference.StartPage);
IContentRepository contentRepository = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<IContentRepository>();
IContentTypeRepository contentTypeRepository = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<IContentTypeRepository>();
SlaegtPage slaegtPage = contentRepository.GetDefault<SlaegtPage>(parent, contentTypeRepository.Load("SlaegtPage").ID);
if (slaegtPage.MainContentArea == null) {
slaegtPage.MainContentArea = new ContentArea();
}
slaegtPage.PageName = "001 …Run Code Online (Sandbox Code Playgroud)