Web site not loading after upgrading to Kentico 11, class removed

Mark Brown asked on April 18, 2018 10:04

Hi all,

I upgraded my web site to K11 but the web site won't load, I have a bunch of errors in VS and I am seeking help.

Here is there Kentico 11 codeupgrade result:

Util.cs";"286";"44";"Class CMS.DocumentEngine.TreeHelper was removed. You can use class CMS.DocumentEngine.DocumentQuery instead.";"CMS.DocumentEngine.TreeNode node = TreeHelper.SelectSingleNode(AliasPath);"

And here is my code:

public static bool DoesNodeExist(string AliasPath)
{
    bool _result = false;

    UserInfo ui = MembershipContext.AuthenticatedUser;

    //TreeProvider tree = new TreeProvider(ui);
    CMS.DocumentEngine.TreeNode node = TreeHelper.SelectSingleNode(AliasPath);
    if (node != null)
    {
        _result = true;
    }
    return _result;
}

What should I do to fix the issue? Thank you very much for your help.

Correct Answer

Vukasin Andjelic answered on April 18, 2018 13:16

Hi Mark,

you need to include System.Linq for FirstOrDefault in code.

Or use code like this :

 public static bool DoesNodeExist(string AliasPath)
    {
    bool _result = false;

    UserInfo ui = MembershipContext.AuthenticatedUser;

    //TreeProvider tree = new TreeProvider(ui);
    var nodes = DocumentHelper.GetDocuments().Column(nameof(TreeNode.NodeAliasPath)).WhereEquals(nameof(TreeNode.NodeAliasPath), "blabla");
    TreeNode node = null;
    if (nodes != null && nodes.Count > 0)
    {
        node = nodes.FirstObject;
    }

    if (node != null)
    {
        _result = true;
    }
    return _result;
}

I hope this will help you Best regards

1 votesVote for this answer Unmark Correct answer

Recent Answers


Prashant Verma answered on April 18, 2018 11:05

Hi Mark,

You facing an issue due to class CMS.DocumentEngine.TreeHelper removed in kentico 11 instead of using CMS.DocumentEngine.TreeHelper use this CMS.DocumentEngine.DocumentQuery.

For more API change log refer this URL https://devnet.kentico.com/documentation/api-changes/kentico-11

You can search here for classes removed in Kentico 11.

Note: During any kentico upgrade if you implement custom code logic you must need to update it with new alternative solution.

Thanks

Happy to help you

0 votesVote for this answer Mark as a Correct answer

Vukasin Andjelic answered on April 18, 2018 11:14 (last edited on April 18, 2018 11:22)

Hi Mark,

you can try something like this

public static bool DoesNodeExist(string AliasPath)
    {
        bool _result = false;

    UserInfo ui = MembershipContext.AuthenticatedUser;

    CMS.DocumentEngine.TreeNode node = DocumentHelper.GetDocuments().WhereEquals("NodeAliasPath", AliasPath).FirstOrDefault();
    if (node != null)
    {
        _result = true;
    }
    return _result;
}

Also, it will be much better if you set which columns to return, this will speed up this query.

DocumentHelper.GetDocuments().Column("NodeAliasPath").WhereEquals("NodeAliasPath", AliasPath).FirstOrDefault();

0 votesVote for this answer Mark as a Correct answer

Mark Brown answered on April 18, 2018 12:49 (last edited on April 18, 2018 13:25)

Hi Vukasin,

Thank you for your help. It worked!

0 votesVote for this answer Mark as a Correct answer

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