Get IUSER by Attribute value

Vote:
 

I am stuck with this...

I am trying to retrieve an IUSER by an Attribute value.
I think I am in the right direction but I can't figure out what's wrong with the ICollection, also not sure this will retrieve the IUSER

 

UserQuery query = new UserQuery();
StringCriterion criteria = new StringCriterion();
criteria.Value = "VALUE";
query["ATTRIBUTE"] = criteria;
query.UserName = new StringCriterion();
ICollection<string> myCollection;
QueryHandler myUser = QueryHandler.GetQueryResult<

User, myCollection>(query);
#30005
May 26, 2009 23:50
Vote:
 

Hi Saar,

It seems like you got the query a bit wrong, it should look something like this:

UserQuery query = new UserQuery();
StringCriterion criteria = new StringCriterion();
criteria.Value = "VALUE";

// Optionally you can specify a wildcard type
criteria.WildCardType = WildCardType.Trailing;

query["ATTRIBUTE"] = criteria;
UserCollection myUser = QueryHandler.GetQueryResult<User, UserCollection>(query);

This query will assume that you have created an attribute of type System.String for the type EPiServer.Common.Security.IUser in the Edit mode. The attribute will have the name "ATTRIBUTE" - remember that it has to named exactly that.

Best regard,
Tom Stenius

#30041
Edited, May 27, 2009 21:01
Vote:
 

Please help, I got this far but I can't seem to get anything back. 

Idealy I would get the IUSER but the username would do.

UserQuery query = new UserQuery();
StringCriterion criteria = new StringCriterion();
criteria.Value = "16044646";
query["SomeValue"] = criteria;
UserCollection myCollection = QueryHandler.GetQueryResult(query);
IEnumerator myEnumerator = myCollection.GetEnumerator();
while (myEnumerator.MoveNext())
{
InfoLabel.Text += myEnumerator.Current.ToString();
}

#30080
May 30, 2009 0:28
Vote:
 

figured it out, posting so maybe someone in the future will benefit

 

 Get IUSER by attribute value:



UserQuery query = new UserQuery();
StringCriterion criteria = new StringCriterion();
criteria.Value = "AttributeValue";
query["AttributeName"] = criteria;
UserCollection myCollection = QueryHandler.GetQueryResult(query);
foreach (IUser myUser in myCollection)
{
Response.Write(myUser.Alias);
}

 

#30081
Edited, Jun 01, 2009 0:54
Vote:
 

Great!

//Tom

#30086
Jun 01, 2009 9:20
This thread is locked and should be used for reference only. Please use the Legacy add-ons forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.