I want to create a Structure Group in Tridion 2011 using core services Any idea?
Asked
Active
Viewed 475 times
-1
-
Have you tried it? Do you really need to ask here how to do something that requires 3 lines of code? – Nuno Linhares May 31 '12 at 13:37
2 Answers
8
This is the code:
var structureGroup = ClientAdmin.GetDefaultData(ItemType.StructureGroup, "tcm:0-2-1");
structureGroup.Title = "SG";
structureGroup.Directiry = structureGroup.Title.Replace(" ", ""),
structureGroup = (StructureGroupData) ClientAdmin.Create(structureGroup, new ReadOptions());
I don't think that any explanations are needed here, if you want to know more - check StructureGroupData
class in CoreService API docs

Andrey Marchuk
- 13,301
- 2
- 36
- 52
-
4Also instead of publication ("tcm:0-2-1"), you can specify another Structure Group as parent item. – Igor Paniushkin May 31 '12 at 08:23
2
The code above doesn't seem to be an standard Core Services API. Check this one.
CoreServiceClient channel = new CoreServiceClient("basicHttp_2011");
string organizationalItemId = "tcm:6-3-4";
StructureGroupData sg = new StructureGroupData();
sg.Id = "tcm:0-0-0";
sg.Title = "NewSG";
sg.LocationInfo = new LocationInfo() { OrganizationalItem = new LinkToOrganizationalItemData() { IdRef = organizationalItemId } };
sg.Directory = "NewSG";
sg = (StructureGroupData)channel.Save(sg, new ReadOptions());
You might note there that the Directory property cannot contain blank spaces. That is because it is validated by a regular expression. You can change it in the file cm_xml_usr.xsd located at [TRIDION_HOME]\bin.

Eric Huiza
- 393
- 1
- 4