This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

com api - getuserlist() KeyNamedPair

I'm writing a script to generate the user list in our environment. using the method - Getuserlist() I can get the number of users using .Count. However that seems like all I can do with it? The type is listed as a KeyNamedPair, not KeyValuePair which means there's not an explicit or implicit conversation that seems to work. I guess really thats question, is it possible to convert to a type I can use to produce the list of user accounts? I tried dictionaries, lists, namedvaluecollections etc.. no matter how I do the conversation I always get the same error about the com object not being able to be converted. Any ideas here?

Parents
  • the specific error - 

    Unable to cast COM object of type 'System.__ComObject' to interface type 'MFilesAPI.IKeyNamePairs'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{9F896259-C49C-4104-8F05-42EA32872BEE}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

    the code - 

    IKeyNamePairs item = vault.UserOperations.GetUserList();

    Console.WriteLine("Number of accounts in " + item.Count);
    //Console.WriteLine(item.Cast<string>());

    var list = new List<string>();

    foreach (IKeyNamePairs pair in item)
    {

    list.Add(pair.ToString());

    }

  • Our collections are a little awkward.  The method returns an instance of IKeyNamePairs, but each item within it will be an IKeyNamePair.  Note the single/plural difference.  Something like this should work:

    var list = new List<string>();
    {
        IKeyNamePairs item = vault.UserOperations.GetUserList();
        
        Console.WriteLine("Number of accounts in " + item.Count);
        
        foreach (var pair in item.Cast<IKeyNamePair>())
        {
            list.Add(pair.Name);
        }
    }

    That said, I don't know whether I've used this API method and so I don't know exactly what it'll return.  Might I suggest instead GetUserAccounts?  The reason I suggest that is that you get much more data back (the entire UserAccount data).

  • That worked, thank you for that. I'll take a look at GetUserAccounts

Reply Children
No Data