Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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");"?
Hi Bram, you could use the GetNodesByName, or GetChildNodeByName methods of this helper class.
HTH,
Hendy
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();
thx Kipusoep,this will do the job for me.
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
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:
Is there a way to do this "Document.getDocumentWithName("2010");"?
Hi Bram, you could use the GetNodesByName, or GetChildNodeByName methods of this helper class.
HTH,
Hendy
thx Kipusoep,
this will do the job for me.
is working on a reply...