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.

  • 1
    What code have you already tried? – Chris Morgan Jul 15 '15 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). :-) – Alvin Reyes Jul 17 '15 at 16:48
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

| improve this answer | |
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);
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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