以图书形式创建文档Kentico 9

时间:2016-05-25 15:07:15

标签: c# kentico

我在后端创建了一个新文档,但在Kentico 9中找不到有关如何执行此操作的任何有用信息。

到目前为止,我已经

 UserInfo user = UserInfoProvider.GetUserInfo("administrator");

// Creates a tree provider instance using administrator context
TreeProvider tree = new TreeProvider(user);

// Prepare parameters
string siteName = CMS.SiteProvider.SiteContext.CurrentSiteName;
string aliasPath = "/News";
string culture = "en-GB";
bool combineWithDefaultCulture = false;
string classNames = TreeProvider.ALL_CLASSNAMES;
string where = null;
string orderBy = null;
int maxRelativeLevel = -1;
bool selectOnlyPublished = false;
string columns = null;

// Get the example folder
TreeNode parentNode = DocumentHelper.GetDocument(siteName, aliasPath, culture, combineWithDefaultCulture, classNames, where, orderBy, maxRelativeLevel, selectOnlyPublished, columns, tree);

if (parentNode != null)
{
  // Create a new node
  TreeNode node = TreeNode.New("CMS.News", tree);

  // Set the required document properties
  node.DocumentName = "Test";
  node.DocumentCulture = "en-GB";

  // Insert the document
  try
  {
    DocumentHelper.InsertDocument(node, parentNode, tree);
  }
  catch (Exception ex)
  {
    EventLogProvider.LogException("Create New News", "EXCEPTION", ex);
  }
}

然而这会引发错误:

Message: [WebFarmTaskManager.CanCreateTask]: Task type 'DICTIONARYCOMMAND' is not supported. The task needs to be registered with WebFarmHelper.RegisterTask method.

有没有人有过在Kentico 9 这样做的经验?

2 个答案:

答案 0 :(得分:4)

对不起,可能是我的两分钱来得太晚但是我解决了调用Kentico docs中没有提到的以下初始化方法的相同问题:

CMS.DataEngine.CMSApplication.Init();

答案 1 :(得分:2)

您可以在内容树中创建页面,如:

// Creates a new instance of the Tree provider
TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);

// Gets the current site's root "/" page, which will serve as the parent page
TreeNode parentPage = tree.SelectSingleNode(SiteContext.CurrentSiteName, "/", "en-us");

if (parentPage != null)
{
// Creates a new page of the "CMS.MenuItem" page type
TreeNode newPage = TreeNode.New(SystemDocumentTypes.MenuItem, tree);

// Sets the properties of the new page
newPage.DocumentName = "Articles";
newPage.DocumentCulture = "en-us";

// Inserts the new page as a child of the parent page
newPage.Insert(parentPage);

您可以在版本9的API Examples文档中找到更多示例。