{"id":1079,"date":"2011-08-02T18:22:27","date_gmt":"2011-08-02T23:22:27","guid":{"rendered":"http:\/\/blogs.devhorizon.com\/reza\/?p=1079"},"modified":"2011-08-02T18:32:51","modified_gmt":"2011-08-02T23:32:51","slug":"detecting-the-personalized-view-of-a-publishing-page","status":"publish","type":"post","link":"https:\/\/blogs.devhorizon.com\/reza\/2011\/08\/02\/detecting-the-personalized-view-of-a-publishing-page\/","title":{"rendered":"Detecting the Personalized View of a Publishing Page"},"content":{"rendered":"<p>The requirement is pretty straightforward : Show a coaching statement in each Web Part placed in the personalized view (personalized view != shared view).<\/p>\n<p>One would imagine that <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/microsoft.sharepoint.webcontrols.spcontrolmode%28v=office.12%29.aspx\">SPContext.Current.FormContext.FormMode<\/a> would let you detect if a page is put in the personalized view, but that&#8217;s not the case! Instead, Web Part manager handles this.<\/p>\n<p>To accomplish this, do the following in your Web Part:<\/p>\n<p>[CSharp]<br \/>\nif (WebPartManager.GetCurrentWebPartManager(this.Page).Personalization.Scope == PersonalizationScope.User)<br \/>\n{<br \/>\n  this.Label1.Text = &#8220;In personalized view&#8221;;<br \/>\n}<br \/>\n[\/CSharp]<\/p>\n<p>Obviously, if you wanted to target the shared view, you could change PersonalizationScope.User to PersonalizationScope.Shared in your if condition.<\/p>\n<p><a href=\"https:\/\/blogs.devhorizon.com\/reza\/wp-content\/uploads\/2011\/08\/personalized.png\" title=\"personalized.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blogs.devhorizon.com\/reza\/wp-content\/uploads\/2011\/08\/personalized.png\" alt=\"personalized.png\" width=\"429\" height=\"164\" \/><\/a><\/p>\n<p><a href=\"https:\/\/blogs.devhorizon.com\/reza\/wp-content\/uploads\/2011\/08\/shared.png\" title=\"shared.png\"><img decoding=\"async\" src=\"https:\/\/blogs.devhorizon.com\/reza\/wp-content\/uploads\/2011\/08\/shared.png\" alt=\"shared.png\" \/><\/a><\/p>\n<p>While you are in each scope , it&#8217;s easy to toggle to the other one using the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.web.ui.webcontrols.webparts.webpartpersonalization.togglescope%28v=vs.90%29.aspx\">WebPartPersonalization.ToggleScope<\/a> method.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;s not the case! Instead, Web Part manager handles this. To accomplish [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-1079","post","type-post","status-publish","format-standard","hentry","category-sharepoint-2010"],"_links":{"self":[{"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/posts\/1079","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/comments?post=1079"}],"version-history":[{"count":0,"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/posts\/1079\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/media?parent=1079"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/categories?post=1079"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/tags?post=1079"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}