In this post, we will discuss how we can retrieve all SharePoint users into a custom list using event receiver feature in SharePoint 2010.
Also you can check out:
1. First create Empty SharePoint project using visual studio 2010.
2. Now add the custom list definition for fetching the user in your project.
3. In solution explorer find the feature, if missing create feature.
4. Click this feature and Add Event Receiver. See in fig
5. Now open the Feature2.EventReceiver.cs file and remove the comment from FeatureActivated method and under this method add the following code.
public override void FeatureActivated(SPFeatureReceiverProperties properties)
currentsite = (SPSite)properties.Feature.Parent;
rootweb = currentsite.RootWeb;
rootweb.AllowUnsafeUpdates = true;
userCollection = rootweb.AllUsers;
if (userCollection.Count > 0)
CustomUserInformationList = rootweb.Lists[“UserInformation Lst”];
//UserInformation Lst is a custom list where we show the all user
foreach (SPUser user in userCollection)
newItem = CustomUserInformationList.Items.Add();
newItem[“Title”] = user.ToString();
// Title is the column of UserInformation Lst
rootweb.AllowUnsafeUpdates = false;
6. Now Save and deploy the solution.
7. Now you go you SharePoint site and click your custom list and see the all user listed in your SharePoint. See in fig
You May Also like the Following SharePoint Tutorials: