Skip to main content
(While we are at it - action by user 5533 (sesan) at 2023-03-04T042535Z0.) Copy edited (e.g. ref. <https://en.wiktionary.org/wiki/you#Pronoun>). Reduced the indentation for readability here (horizontal scrolling).
Source Link

So If you have the title for the keyword and know the category attached to the component field, Youyou can use below function to get the keyword id.

string GetKeywordId(string KeywordTitle, string categoryID)
        {
            KeywordsFilterData kwdFilter = new KeywordsFilterData();
            
            var query1 = from XElement r1 in tridionClient.GetListXml(categoryID, kwdFilter).Descendants()
                         where r1.Attribute("Title").Value.ToLower() == KeywordTitle.ToLower()
                         select r1;
            XElement foundNode = query1.FirstOrDefault();
            if (foundNode != null)
            {
                   string keywordID = foundNode.Attribute("ID").Value;
                   return keywordID;
            }

            return "";
        }

So If you have title for the keyword and know the category attached to the component field, You can use below function to get the keyword id.

string GetKeywordId(string KeywordTitle, string categoryID)
        {
            KeywordsFilterData kwdFilter = new KeywordsFilterData();
            
            var query1 = from XElement r1 in tridionClient.GetListXml(categoryID, kwdFilter).Descendants()
                         where r1.Attribute("Title").Value.ToLower() == KeywordTitle.ToLower()
                         select r1;
            XElement foundNode = query1.FirstOrDefault();
            if (foundNode != null)
            {
                   string keywordID = foundNode.Attribute("ID").Value;
                   return keywordID;
            }

            return "";
        }

If you have the title for the keyword and know the category attached to the component field, you can use below function to get the keyword id.

string GetKeywordId(string KeywordTitle, string categoryID)
{
    KeywordsFilterData kwdFilter = new KeywordsFilterData();

    var query1 = from XElement r1 in tridionClient.GetListXml(categoryID, kwdFilter).Descendants()
                 where r1.Attribute("Title").Value.ToLower() == KeywordTitle.ToLower()
                 select r1;
    XElement foundNode = query1.FirstOrDefault();
    if (foundNode != null)
    {
           string keywordID = foundNode.Attribute("ID").Value;
           return keywordID;
    }

    return "";
}
Source Link
Saurabh Gangwar
  • 6.5k
  • 1
  • 16
  • 32

So If you have title for the keyword and know the category attached to the component field, You can use below function to get the keyword id.

string GetKeywordId(string KeywordTitle, string categoryID)
        {
            KeywordsFilterData kwdFilter = new KeywordsFilterData();
            
            var query1 = from XElement r1 in tridionClient.GetListXml(categoryID, kwdFilter).Descendants()
                         where r1.Attribute("Title").Value.ToLower() == KeywordTitle.ToLower()
                         select r1;
            XElement foundNode = query1.FirstOrDefault();
            if (foundNode != null)
            {
                   string keywordID = foundNode.Attribute("ID").Value;
                   return keywordID;
            }

            return "";
        }