Bulk changing documents to specific categories

paul carter asked on October 17, 2019 14:39

Hi , I am currently in the process of performing assigning a number of pages in our portal engine to various categories. I am looking at a method something like :

    var docs = DocumentHelper.GetDocuments()
        .Path("/Path", PathTypeEnum.Children)
        .OnCurrentSite();

    foreach (TreeNode node in docs)
    {
        DocumentCategoryInfoProvider.AddDocumentToCategory(node.DocumentID, <categoryId>)
    }

In order to run this code what is the best practice for running the code in the portal engine, ie would i just create a button on a web part to execute it , or create an ascx control and link in as web part. I am thinking ahead in respect to creating a number of utility methods over time.

Recent Answers


Dmitry Bastron answered on October 17, 2019 14:51

Hi Paul,

In this case I'd recommend to look at custom admin interface for it. Here is an article how to create it.

Also, this specific case with assigning pages to categories could be completed by Kentico Import Toolkit (a part of Kentico installation). If you prepare an Excel/csv file with a list of articles and a list of categories you would be able just to import it I think.

0 votesVote for this answer Mark as a Correct answer

paul carter answered on October 17, 2019 14:54

Many thanks, when you say articles i am assuming you are referring to documents.

0 votesVote for this answer Mark as a Correct answer

David te Kloese answered on October 18, 2019 09:50

In case the logic is straight forward;

  • something like all pages go to cat-x
  • or based on path connect to category-y
  • if page has property-z set.
  • etc.

you could also look into create a scheduled task, that can still only run when manually started. docs.kentico.com/.../scheduling-custom-tasks. Can even give it parameters like starting path to add some flexibility.

This has benefit of not needing to create a UI in a custom module and you can schedule it.

0 votesVote for this answer Mark as a Correct answer

paul carter answered on October 18, 2019 10:04

Thanks guys for your help. Looks like i have a bit of ammunition to go with. One final point, what if i want to reverse the changes. Not trying to be pessimistic, but always like to err on the side of caution.

0 votesVote for this answer Mark as a Correct answer

David te Kloese answered on October 18, 2019 10:10

Requires a bit more knowledge of what you're trying to do.

If you can identify what has been changed based on the assigned category you could just loop through everything and disconnect it.

But if being connected to that category doesn't automatically mean it was part of this "bulk edit" you either need to create a mark or log (can be just a custom table).

I'm not 100% sure it covers the categorie-page relateion, but might want to look into workflow and/or versioning docs.kentico.com/api11/content-management/page-workflow-and-versioning

0 votesVote for this answer Mark as a Correct answer

paul carter answered on October 18, 2019 10:30

Hi, effectively. I am looking at grouping pages into a number of categories so that we can then apply a search filter to the specific categories with the relevant content, rather than list hundreds of categories. Hope this helps

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.