I've to create a new document in the back end but can not find any useful information on how to do this in Kentico 9.
So far I've got
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);
}
}
This however throws an error:
Message: [WebFarmTaskManager.CanCreateTask]: Task type 'DICTIONARYCOMMAND' is not supported. The task needs to be registered with WebFarmHelper.RegisterTask method.
Has anyone had experience with doing this in Kentico 9?
Sorry, may be my two cents comes too late but I solved the same issue invoking the following initialization method not mentioned on Kentico docs:
CMS.DataEngine.CMSApplication.Init();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With