5

I am trying to retrieve all usernames. I can get the TCM, and the Title but need to get the Username Filed. When using;

var users = client.GetSystemWideList(new UsersFilterData());
user.id
user.title

I can retrieve only the ID and Title. How do I get the actual name, the full name/desctiption?

6

The GetSystemWideList() gives you a very limited set of data. You need to drill into the data by loading the full UserData object.

This is explained in this answer, did this work for you?

var allUsers = _session.GetSystemWideList(new UsersFilterData { IsPredefined = false, BaseColumns = ListBaseColumns.IdAndTitle });
foreach (var user in allUsers)
{
   var userData = (UserData) _session.Read(user.Id, new ReadOptions());
   string userName = user.Title;
   bool isAdministrator = user.Privileges == 1 ? true : false;
   var groupMemberships = user.GroupMemberships.Select(g => g.Group.IdRef);
}
  • Yes, that worked. I used your example above and added some other code from other examples. I need all user info. How do I load the full UserData object? Here is what I have for retrieving all groups with users. – BryanD Jun 28 '13 at 13:11
  • var users = client.GetSystemWideList(new UsersFilterData()); foreach (var user in users) { string UseID = user.Id; string UseName = user.Title; UserData guser = (UserData)client.Read(user.Id, null); foreach (GroupMembershipData groupMembershipData in guser.GroupMemberships) { using (StreamWriter writer = new StreamWriter("C:\\temp\\TridionUsers\\TridionUsersProduction.txt", true)) { writer.WriteLine("{0},{1}", groupMembershipData.Group.Title, guser.Description); } } – BryanD Jun 28 '13 at 13:14
2

When you say "username" I think of the Windows username (i.e. DOMAIN\userName). If that is what you want, that is actually the Title of a user so you already have it.

If you wish to get the Description, which normally has the "friendly" name of a user such as "Peter Kjaer", you should cast the entries in the list to TrusteeData (as GetSystemWideList returns an array of IdentifiableObjectData which pretty much only have ID and Title available)

Anyway, here's some sample code for you which outputs both values as well as the ID of all users:

private static void ListAllUsers()
{
    using (var client = GetCoreServiceClient())
    {
        var filter = new UsersFilterData { IsPredefined = false};
        var users = client.GetSystemWideList(filter);
        foreach (TrusteeData user in users)
        {
            Console.WriteLine("{0} ({1})= {2}", user.Title, user.Id, user.Description);
        }
    }
}
  • You left us hanging! :) If you see this, please mark an answer as accepted (if it answered your question) or let us know why the answers were not applicable so that we can hopefully provide a better answer. Thanks! – Peter Kjaer Sep 26 '13 at 9:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.