Search code examples
c#tridiontridion-2011xelement

How to get particular tcm uri based on description in Tridion using core services?


I get the list of all users in XElement in Tridion using core services. Now I want to search for a particular user's tcm uri based on the decription?


Solution

  • You could use the LINQ to query by the description to get the user TCMURI. This is just one of the approach since you alread have XElement of userlist. You could just use the GetSystemWideList and perform LINQ operations on that as well.

         XElement userListXml = _client.GetSystemWideListXml(
                new UsersFilterData { 
                       BaseColumns = ListBaseColumns.Default, 
                       IsPredefined = false 
                 });
    
         // LINQ to query by description
        var user = (from el in userListXml.Elements()
                    where (string) el.Attribute("Description") == "USERDESCRIPTON" 
                    select el).FirstOrDefault();
    
        string usrTcmURI = user.Attribute("ID").Value;