I want to make it generic method if we want to read the component template id based on the component template name for any publication or folders it should work.
Need to be done using C# and want to return the component template ID and the component template name
String[] arrctNames = new String[[%=i%]];
int[] arrctIds = new int[[%=i%]];
[%
i = 0
For Each Node In NodeList
%]
arrctNames[[%=i%]] = "[%=Node.getAttribute("Title")%]";
arrctIds[[%=i%]] = [%=Mid(Node.getAttribute("ID"), I
nStr(Node.getAttribute("ID"),"-") + 1, Len(Node.getAttribute("ID")) -InStr(Node.getAttribute("ID") ,"-") - ( 1 + Len(Node.getAttribute("ID")) - InStr(InStr(Node.getAttribute("ID") ,"-")+1,Node.getAttribute("ID") ,"-")))%];
[%
i = i + 1
Next
Set NodeList =Nothing
%]
for(int i=0;i<arrctNames.length;i++)
{
//check if the ct name matches with the string
//if(!(arrctNames[i].toUpperCase().indexOf(componentTemplateName.toUpperCase()) == -1))
if(arrctNames[i].toUpperCase().equals(componentTemplateName.toUpperCase()))
{
return arrctIds[i];
}
}
return -1;
}
the above mentioned code is in java.
I want to do the same thing using the c# .
The current output rendered in this format:
String[] arrctNames = new String[125];
int[] arrctIds = new int[125];
arrctNames[0] = "CT";
arrctIds[0] = 1;
The similar way want to do in the C#.
For the conversion i have started i'm starting in the right way please suggest me
RepositoryItemsFilter filter = new RepositoryItemsFilter(_engine.GetSession());
filter.ItemTypes = new ItemType[] { ItemType.ComponentTemplate };
filter.Recursive = true;
Publication pub = this.GetPublication();
int i;
String[] arrctNames = new String[i];
int[] arrctIds = new int[i];
foreach (XmlNode node in pub.GetListItems(filter).ParentNode.ChildNodes)
{
string ctId = node.Attributes["ID"].Value;
string ctname = node.Attributes["Title"].Value;
}
GetListItems()
method in the API docs and online documentation. That should give you a start.