首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >以进步方式创建文档Kentico 9

以进步方式创建文档Kentico 9
EN

Stack Overflow用户
提问于 2016-05-25 15:07:14
回答 2查看 807关注 0票数 3

我必须在后端创建一个新文档,但是无法在Kentico 9中找到任何有用的信息。

到目前为止我有

代码语言:javascript
复制
 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);
  }
}

然而,这会引发一个错误:

代码语言:javascript
复制
Message: [WebFarmTaskManager.CanCreateTask]: Task type 'DICTIONARYCOMMAND' is not supported. The task needs to be registered with WebFarmHelper.RegisterTask method.

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

EN

回答 2

Stack Overflow用户

发布于 2016-07-08 16:21:35

对不起,也许我来的太晚了,但是我解决了调用Kentico文档中没有提到的以下初始化方法的相同问题:

代码语言:javascript
复制
CMS.DataEngine.CMSApplication.Init();
票数 4
EN

Stack Overflow用户

发布于 2016-05-25 15:20:27

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

代码语言:javascript
复制
// 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示例文档中找到更多的示例。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37441094

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档