Copied to clipboard

Flag this post as spam?

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


  • Bram Loquet 72 posts 102 karma points
    May 18, 2010 @ 11:02
    Bram Loquet
    0

    How do I check if there is already a node with this namen

    I want to add some 'year'-folders for a news-section so I first want to check if the year already exsists, if not I'll add it.

    Something like the code below:

    Document existingDoc = Document.getDocumentWithName("2010");

    if (!docParent.Children.Contains<Document>(existingDoc))
    {
    }

    Is there a way to do this "Document.getDocumentWithName("2010");"?

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    May 18, 2010 @ 11:06
    Hendy Racher
    0

    Hi Bram, you could use the GetNodesByName, or GetChildNodeByName methods of this helper class.

    HTH,

    Hendy

  • Stefan Kip 1614 posts 4131 karma points c-trib
    May 18, 2010 @ 11:23
    Stefan Kip
    1
    Document objParent = new Document(doc.Parent.Id);
         int iYear = DateTime.Now.Year;
         int iMonth = DateTime.Now.Month;
         int iDay = DateTime.Now.Day;
         Document objYearFolder;
         if (objParent.Children.Where(x => x.ContentType.Alias == "Content Folder" && x.Text == iYear.ToString()).ToList().Count < 1)
         {
          // Create year folder
          objYearFolder = Document.MakeNew(iYear.ToString(), DocumentType.GetByAlias("Content Folder"), doc.User, objParent.Id);
          objYearFolder.Publish(doc.User);
          umbraco.library.UpdateDocumentCache(objYearFolder.Id);
          int iSortOrder = 0;
          foreach (Document objChild in objParent.Children.OrderBy(x => x.Text))
          {
           objChild.sortOrder = iSortOrder;
           objChild.Save();
           iSortOrder++;
          }
         }
         else
          objYearFolder = objParent.Children.Where(x => x.ContentType.Alias == "Content Folder" && x.Text == iYear.ToString()).ToList().FirstOrDefault();
  • Bram Loquet 72 posts 102 karma points
    May 18, 2010 @ 12:02
    Bram Loquet
    0

    thx Kipusoep,
    this will do the job for me.

Please Sign in or register to post replies

Write your reply to:

Draft