Background: I have developed a couple of SharePoint 2010 web parts using Visual Studio with custom properties. I have also been able to set these properties with code so that they persist. I also know that SharePoint users can personalize pages & web parts with their own property values etc.
Question: Is it possible to set up a property that is always only user-specific?
In other words, I want my web part to have a property that starts out blank and is assigned a value once a user performs an action within the web part, but that value is specific to that user. Other users viewing the page would need to perform that action to get their own value. I would like for this to happen without the users having to manually personalize the page.
I tried setting attributes:
Personalizable( PersonalizationScope.User )
and later added
WebPartStorage( Storage.Personal )
and did some testing, but the value set by the first user always persisted to the second.
We haven't done a lot with personalization, so I'm really just curious if this is even possible.
You should be able to add an attribute [Personalizable(true)]
.
The WebPartStorage
property (with Storage.Shared
and Storage.Personal
) is a holdover from the older API for SharePoint 2003, as documented here.
Take a look at Microsoft's walkthrough article here: Creating a Custom Web Part Editor in SharePoint 2010
The Web Part declares a private variable _tabList as a collection of TabData objects. This collection is wrapped through the TabList property. The property returns an empty collection if _tabList is null. The property is also marked Personalizable, to enable users to customize the tabs.
[...]
// Collection of tabs. private List<TabData> _tabList; // Property to hold the collection of tabs. // Set the Personalizable attribute to true, // to allow for personalization of tabs by users. [Personalizable(true)] public List<TabData> TabList { get { if (this._tabList == null) { // Return an empty collection if null. this._tabList = new List<TabData>(); } return this._tabList; } set { this._tabList = value; } }
For more reading, check out Microsoft's documentation here: About Web Part Page personal and shared views
Notably, consider the following excerpt:
When a Web Part page is in personal page view, you:
- Can usually view and modify the Layout and Appearance common Web Part properties, but not the Advanced ones. In some cases, the developer of a Web Part may decide not to display some or all common properties or you may not have permission to see them.
- Can view and modify custom Web Part properties. In some cases, the developer of a Web Part may decide not to display some or all custom properties or you may not have permission to see them.
- Can view and modify, but not delete, shared Web Parts with appropriate permission. Once you modify a shared Web Part, however, it becomes a personalized Web Part.
- Can view and modify, but not delete, personalized Web Parts. The modified property values of these Web Parts apply only to you.
- Can view, modify, and delete private Web Parts. These Web Parts only apply to you, no other users can see them, even in shared view.
By default, only Layout and Appearance properties are customized to the current user when editing a page in personal view. Custom properties are shared unless you explicitly make them personalizable.