开发者

Get user email programmatically if I have user guid? (SharePoint)

Currently I have a method to get all the users in a site collection and databind this to a dropdown.

private void getUsers()
{
    SPGroupCollection collGroups = SPContext.Current.Web.Groups;


    foreach (SPGroup oGroup in collGroups)
    {
        foreach (SPUser oUser in oGroup.Users)
        {
            ddlSiteOwner.Items.Add(new ListItem(oUser.Name, oUser.ID.ToString()));
        }
    }
}

Is there a way to get users based on their guid? I select a user in the dropdown with guid as value and I would like to use this to search for the users email.

I tried something like

private string getUserEmail(string userGuid)
{
    string userEmail = null;
    SPGroupCollection collGro开发者_如何转开发ups = SPContext.Current.Web.Groups;

    foreach (SPGroup oGroup in collGroups)
    {
        foreach (SPUser oUser in oGroup.Users.GetByID(userGuid))
        {
            userEmail = oUser.Email;
        }
    }
    return userEmail;
}

But with GetByID it wants 32bit integer and not a guid so how would I achieve this? Thanks in advance.

Edit: saw that users don't have guids but sids now.


The SPUser.ID property you are using in your dropdown is an integer, not a guid.

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spuser.id.aspx

So the GetByID should work normally, just parse the value as an integer.

int.Parse(), or int.TryParse()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜