Feb 16, 2010

How to get Site Users and Fill dropdown list

In this example we will get all the site users and fill them in a dropdownlist.

using Microsoft.SharePoint;

string strUrl =configurationManager.ConnectionStrings["SharePointUrl"].ToString();

SPSite spsite = new SPSite(strUrl);

SPWeb web = spsite.OpenWeb();

SPUserCollection UserList = web.SiteUsers;

Int32 count = 0;

foreach (SPUser u in UserList)

{

if (u.ID.ToString() != currentUserId.ToString() && u.Name.ToLower() != userName && u.Name != "System Account" && u.Name != "System Administrator" && u.Name != "SHAREPOINT\\system" && u.Name.ToUpper() != "NT AUTHORITY\\LOCAL SERVICE")

{

string userLoginName = u.LoginName.ToString();

userLoginName = userLoginName.Substring(userLoginName.IndexOf("\\") + 1);

ddlUserListTo.Items.Add(userLoginName.ToUpper());

ddlUserListTo.Items[count].Value = u.ID.ToString();

count += 1;

}

}

2 comments:

Unknown said...

hope you got me.

Unknown said...

Can you give the demo?
I am sure this will not work.
And do paste images also for post to be precise