How to store user-specific data in SharePoint

sharepointsharepoint-2010wss

I have some user-specific data that I need to store in SharePoint and make accessible to the user through custom webparts. Let's say a list of favorite URLs. What would be the most straightforward way to store this information?

  • Some builtin propertybag for SPUser or similar that I'm not aware of.
  • SPList, associated through User column.
  • Custom database table, associated through SPUser ID.
  • Otherwise?

Sounds like a RTFM to me, but I'm probably asking google the wrong questions.

[Update]

We eventually stored this information in a simple list, in a fixed location, with a Person field to filter on. Perhaps the simplest solution indeed, but technically I think the marked answer below is nicer.

Best Answer

If you want to make them reusable across the site collection for each user you can add Fields to the User Information List. You can add a feature receiver to your web parts solution that can create this column or check to see if this column exists in the User information list to be sure that the Column exists.

The User Information list is a Standard SharePoint list that SharePoint uses to store user information. To access the User Information List you can go to the Root web of the Site Collection and use the SiteUserInfoList property

E.G.

SPList userInformationlist = SPContext.Current.Site.RootWeb.SiteUserInfoList;
//Or 
SPWeb web = SPContext.Current.Site.RootWeb;
SPList userInformationlist = web.SiteUserInfoList;

To access a users List Item you can use the Users Id to get the ListItem back from the User Information List

E.G.

SPListItem currentUserItem = userInformationlist.GetItemById(web.CurrentUser.ID);

If you are using MOSS you can store this information in the User Profiles and make it available across Site Collections this does not need My Sites to be enabled. You would need to use the User Profile classes to access this.

Related Topic