Last active
August 15, 2019 14:58
-
-
Save justsayantan/1b161447cb4133e3f13d331b2b7484ca to your computer and use it in GitHub Desktop.
Retrieve Component By Title
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public string getcomponentid() | |
{ | |
var client = Utility.GetCoreServiceSettings(); | |
string result = "Item not found"; | |
string TargetFolderTcmId = @"tcm:5-1945-2"; // Put your folder tcm id here | |
string title = @"Component Title";// Put your component title here | |
var productsXML = | |
client.GetListXml(TargetFolderTcmId, | |
new OrganizationalItemItemsFilterData | |
{ | |
ItemTypes = new[] { ItemType.Component } | |
}); | |
foreach (var product in productsXML.Elements()) | |
{ | |
string tcmID = product.Attribute("ID").Value; | |
var productData = client.Read(product.Attribute("ID").Value, null) as ComponentData; | |
// Check your title | |
if (productData.Title == title) | |
{ | |
return tcmID; | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment