Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • berex 7 posts 77 karma points
    Jun 05, 2018 @ 09:15
    berex
    0

    Check if content page already exists

    I am creating content pages programmacatically. I would like to check if the page was created before creating again.

    How do I retrieve a content page by alias to see if it exists already?

  • Alex Brown 129 posts 620 karma points
    Jun 05, 2018 @ 10:28
    Alex Brown
    2

    If you're creating content which has the same document type then you might have to search by name.

    If you get the root node you can search its descendants and detect if there's any which match the name. You should specify the document type in DescendantOrSelf() to narrow the results down (just in case you have nodes with the same name).

    E.g.

    var nodeExists = new UmbracoHelper(UmbracoContext.Current).TypedContentAtRoot().DescendantsOrSelf("documentType").Any(n => n.Name == nameVariable);
    
  • berex 7 posts 77 karma points
    Jun 05, 2018 @ 13:32
    berex
    0

    Hi thanks for your reply... Im having issues with the word Any...

    enter image description here

  • berex 7 posts 77 karma points
    Jun 06, 2018 @ 07:38
    berex
    0

    My bad... had missed the using System.Linq;

    Thanks for help ;)

  • Ethan Scott 3 posts 73 karma points
    Jun 06, 2018 @ 09:57
    Ethan Scott
    0

    Thank you, this helps. What are the parameters that it will compare to check the same?

Please Sign in or register to post replies

Write your reply to:

Draft