Home > SharePoint 2010 > Detecting the Personalized View of a Publishing Page

Detecting the Personalized View of a Publishing Page

August 2nd, 2011 Leave a comment Go to comments

The requirement is pretty straightforward : Show a coaching statement in each Web Part placed in the personalized view (personalized view != shared view).

One would imagine that SPContext.Current.FormContext.FormMode would let you detect if a page is put in the personalized view, but that’s not the case! Instead, Web Part manager handles this.

To accomplish this, do the following in your Web Part:

[CSharp]
if (WebPartManager.GetCurrentWebPartManager(this.Page).Personalization.Scope == PersonalizationScope.User)
{
this.Label1.Text = “In personalized view”;
}
[/CSharp]

Obviously, if you wanted to target the shared view, you could change PersonalizationScope.User to PersonalizationScope.Shared in your if condition.

personalized.png

shared.png

While you are in each scope , it’s easy to toggle to the other one using the WebPartPersonalization.ToggleScope method.

Categories: SharePoint 2010 Tags:
  1. August 2nd, 2011 at 23:42 | #1

    Thanks dear Reza for your usefull post .