Skip to content

Instantly share code, notes, and snippets.

@justsayantan
Last active August 15, 2019 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justsayantan/1b161447cb4133e3f13d331b2b7484ca to your computer and use it in GitHub Desktop.
Save justsayantan/1b161447cb4133e3f13d331b2b7484ca to your computer and use it in GitHub Desktop.
Retrieve Component By Title
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