3

I am new to tridion, I want to create a new folder structure same as existing folder structure by using core service 2011.

My folder structure looks like below

enter image description here

I need to create new folder structure same as "2014 News" folder structure and It should contain same sub folder structures as well.

2
  • 1
    What code have you already tried? Jul 15, 2015 at 15:48
  • 1
    Two things to consider as you approach this requirement: 1. the "context-free" names like "2014 News" are useful when needing to know the folder anywhere. But if you can get away with removing the year from the month folders, then this could be done with just copy&paste. 2. If the editors organize items like this a lot, consider making your code generic enough to copy a set of any folders (with maybe a date parameter). :-) Jul 17, 2015 at 16:48

2 Answers 2

2

First follow something like this post to get all the folders recursively

https://stackoverflow.com/questions/12018111/get-all-folders-of-a-publication-using-core-service

Then this post can help you with creating the new folders

https://stackoverflow.com/questions/9905021/how-to-create-folder-structure-in-sdl-tridion-2011-sp1-using-core-service

2

You just need to know how to create folders within other folders, then add some simple C# looping and formatting logic.

var formatInfo = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat;

var parentFolderUrl = "/webdav/Test Publication/Building Blocks/Content/50 News";

var yearFolder = (FolderData) client.GetDefaultData(ItemType.Folder, parentFolderUrl);

yearFolder.Title = String.Format("2015 News");

yearFolder = (FolderData) client.Save(yearFolder, new ReadOptions());

for (int month = 1; month <= 12; month++)
{
    var monthFolder = (FolderData) client.GetDefaultData(ItemType.Folder, yearFolder.Id);

    monthFolder.Title = String.Format("2015-{0:D2} {1} News",
                            month,
                            formatInfo.GetMonthName(month));

    client.Save(monthFolder, null);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.