Adding functionalities to pages by inheriting PublishingLayoutPage


If you have worked a lot with MOSS you probably know how to make new page layouts. But if you create new page layouts you might sometimes wonder that how could I add some common functionalities to my page layout pages. One example could be localization. You have decided that Variations isn't the way to go in your case, but you still want to have different site structures for different languages... and of course you want to have texts localized. Or you want to change your master page for some reason on the fly... one example could be for printing reasons. Or even wilder... you want to change you page layout to another! You could do this kind of stuff pretty easily if you create your own PublishingLayoutPage class that has support your new functionalities. I'm going to explain how you can do that with SharePoint Designer and Visual Studio.

Create new class that will extend the functionality of PublishingLayoutPage

I started my journey by creating new Class Library project. I named it "Microsoft.MCS.Common" (since I work in MCS inside Microsoft... cool naming right :-). I added new class and named it PublishingLayoutPageEx. I inherited that from PublishingLayoutPage which is class behind page layouts. Where did I got that class name? Well I just opened ArticleLeft.aspx with SharePoint Designer and checked the first line:

<%@ Page language="C#" Inherits="Microsoft.SharePoint.Publishing.PublishingLayoutPage, Microsoft.SharePoint.Publishing, Version=12.0.0.0,Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

So it was pretty obvious that if I want to extend the functionality of the basic publishing page, I needed to inherit from it.

At this point my code looked like this (not much since we just started):
 1  using System;
 2  using System.Collections.Generic;
 3  using System.Text;
 4  using System.Web.UI;
 5  using System.Globalization;
 6  using System.Threading;
 7  using Microsoft.SharePoint.Publishing;
 8  using Microsoft.SharePoint;
 9
10  namespace Microsoft.MCS.Common
11  {
12    public class PublishingLayoutPageEx : PublishingLayoutPage
13    {
14      public PublishingLayoutPageEx()
15        : base()
16      {
17      } 
18    } 
19  }

And now I'm ready to test my new class in action. I just added strong name key, compiled and put it in the GAC. And then I changed the ArticleLeft.aspx to use my new class:

<%@ Page language="C#" Inherits="Microsoft.MCS.Common.PublishingLayoutPageEx, Microsoft.MCS.Common,Version=1.0.0.0, Culture=neutral,PublicKeyToken=b1e9400215c03709" %>

<small sidetrack to .NET Reflector>

If you're interestested in the stuff that's implemented in PublishingLayoutPage, then you can play around with incredible tool: Lutz Roeder's NET Reflector:

In just few clicks we can see that there is some MasterPageFile retrieving in OnPreInit:

</small sidetrack to .NET Reflector>

If you now try your new PublishingLayoutPageEx in action you'll get this kind of error message:


Server Error in '/' Application.

Parser Error

Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: The base type 'Microsoft.MCS.Common.PublishingLayoutPageEx' is not allowed for this page. The type is not registered as safe.

Source Error:


Line 1:  <%@ Page language="C#"   Inherits="Microsoft.MCS.Common.PublishingLayoutPageEx,Microsoft.MCS.Common,Version=1.0.0.0,Culture=neutral,PublicKeyToken=b1e9400215c03709" %>
Line 2:  <%@ Register Tagprefix="SharePointWebControls" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="PublishingWebControls" Namespace="Microsoft.SharePoint.Publishing.WebControls" Assembly="Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="PublishingNavigation" Namespace="Microsoft.SharePoint.Publishing.Navigation" Assembly="Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
Line 3:  <asp:Content ContentPlaceholderID="PlaceHolderPageTitle" runat="server">


Source File: /_catalogs/masterpage/ArticleLeft.aspx    Line: 1


Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.210

 

That only means that we need to mark that component as Safe so that SharePoint will load it. Let's just modify our applications web.config file by adding following line in there:

<SafeControl Assembly="Microsoft.MCS.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b1e9400215c03709" Namespace="Microsoft.MCS.Common" TypeName="PublishingLayoutPageEx" Safe="True" AllowRemoteDesigner="true" />

And then hit F5 in your browser and you should be all set. Now you have base what we're going to extend in next.

Add localization support to your pages

If you haven't played with ASP.NET Resource files, then you should take small detour into www.asp.net localization quickstart

So now you know about .RESX files πŸ™‚ I created Example.resx, Example.en-US.resx and Example.fi-FI. I have added only two words to the resource files:

  1. House:
    • en-US: House
    • fi-FI: Talo
  2. You:
    • en-US: You
    • fi-FI: SinΓ€

I copied those resource files to my applications App_GlobalResouces folder:

C:\Inetpub\wwwroot\wss\VirtualDirectories\80\App_GlobalResources 

Now I modified my default_Janne.master page so that it would receive text from my resource files. I added following line just before </body> in master page.

<asp:Literal ID="house" runat="server" Text="<%$Resources:Example,House%>" /> <-> <asp:Literal ID="you" runat="server" Text="<%$Resources:Example,You%>" />

We have now added resource files and modified master page so that it will take text from our resource file. Let's just add code to our new class so that we could change the language on the fly.

 1  using System;
 2  using System.Collections.Generic;
 3  using System.Text;
 4  using System.Web.UI;
 5  using System.Globalization;
 6  using System.Threading;
 7  using Microsoft.SharePoint.Publishing;
 8  using Microsoft.SharePoint;
 9
10  namespace Microsoft.MCS.Common
11  {
12    public class PublishingLayoutPageEx : PublishingLayoutPage
13    {
14      public PublishingLayoutPageEx()
15        : base()
16      {
17      }
18
19      protected override void OnPreInit()
20      {
21         base.OnPreInit();
22         this.InitializeCulture(); 
23      }
24
25      protected override void InitializeCulture()
26      {
27         if (Request["mylang"] != null)
28         {
29           Thread.CurrentThread.CurrentCulture = new CultureInfo(Request"mylang"].ToString()); 
30           Thread.CurrentThread.CurrentUICulture = new CultureInfo(Request["mylang"].ToString()); 
31         } 
32  
33         base.InitializeCulture(); 
34      } 
35    } 
36  }

And now we can change the language from URL:

Here is result without the mylang parameter:

Of course you might not want to change your language by url parameter πŸ™‚ This is just sample that you CAN do that. Maybe it would be much wiser to use some kind of site structure for localization. But I'll leave that to you...

Change master page on the fly

Now we want to make something fancier... like changing the master page on the fly. You could want to use this for print layouts, smaller screen, mobile etc. But anyway.. You just might want to do that sometimes πŸ™‚

So let's throw some code in here and see what happens:

...
 1      protected override void OnPreInit() 
 2      { 
 3         base.OnPreInit();
 4         if (Request["Print"] != null) 
 5         { 
 6           this.MasterPageFile = "/_catalogs/masterpage/BlueBand.master";
 7         } 
 8      }
... 

On lines 4 to 6 we have just check that if there is mysterious Print parameter set. If that is set, we'll change the master page to nicely hardcode one. Let's see what happens on our browser:

So the result is quite easy to see... our master page changed from default_janne.master to BlueBand.master.

Change the page layout

Before I start... I'm going to give credit of this idea to Vesa Juvonen (colleague of mine at MCS who also works with SharePoint). He said that this would be interesting thing to checkout. And since I happened to have some code ready we tried this stuff on my environment. But he's going to create full solution of this page layout change and publish it in his blog. So you probably want to check that place out too. Okay.. but let's get back to the subject.

This might sound a bit strange but still... sometimes you might want to change page layout after the page has been created. Consider the Article Page content type which is OOB content type in SharePoint. It has 4 different kind of page layouts. User could have selected Image on right layout and has filled the page with data. After a while you want to change it to another layout.... BUT there isn't easy way to do that... unless we'll extend our nice class again.

Idea is take (again) some nice url parameter that tells the destination page layout. In this example I'll just take integer which is used to get the correct page layout from array of possible page layouts of this content type. And yes... I know that this code sample has a lot to improve... It just gives you ideas.

Let's throw some code in here and see what happens:

...
 1      protected override void OnPreInit() 
 2      { 
 3        SPContext current = SPContext.Current;
 4        if (current != null && 
 5            Request["changepagelayout"] != null && 
 6            Request["done"] == null
 7        { 
 8          SPWeb web = current.Web; 
 9          // We need to allow unsafe updates in order to do this: 
10          web.AllowUnsafeUpdates = true
11          web.Update(); 
12          
13          PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web); 
14          PageLayout[] layouts = publishingWeb.GetAvailablePageLayouts(current.ListItem.ContentType.Parent.Id); 
15          PublishingPage publishingPage = PublishingPage.GetPublishingPage(current.ListItem); 
16          publishingPage.CheckOut(); 
17          // This is the magic:
18          publishingPage.Layout = layouts[Convert.ToInt32(Request["changepagelayout"])]; 
19          publishingPage.Update(); 
20          publishingPage.CheckIn("We have changed page layout"); 
21          
22          SPFile file = current.ListItem.File; 
23          file.Publish("Publishing after page layout change"); 
24          // We have content approval on: 
25          file.Approve("Approving the page layout change"); 
26          Response.Redirect(Request.Url + "&done=true"); 
27        } 
28        base.OnPreInit(e);
29      }
... 

And you can right away see from code that there isn't any checks or any error handling. So this code is only for demonstration purposes and you shouldn't take it any other way.... but here we can see the results after user has type in parameter changepagelayout=1 (Image on left):

And here is page if parameter is 2 (Image on right).

If you look at the code on line 14 where page layouts are retrieved... I'm using Parent of the current content type. You might ask why... But the reason is simple since your content type from the list actually inherits the Article Page content type from Site collection level. So if you would use ListItem.ContentType you wouldn't get those 4 page layouts of Article Page. Insted you need to get the parent of the content type in the list and then you get 4 different page layouts. Makes sense if you think how inheritance in SharePoint works.

If you wonder that done parameter I'm using... It is just helper to avoid recursive page layout change πŸ˜‰

Note: If you look at the code you probably already noticed that it's not changing the layout for this rendering... it has changed the page layout permanently. Of course you can change it back if you want to.

Summary

You can use a lot of stuff from ASP.NET right in your SharePoint page layouts. I can't even imagine all the capabilities of this but I'm just going to give you brief list what I can think of now:

1) Localization:

  • This one is obvious πŸ™‚ I live in Finland and we need to deal with this in every project.

2) Change the master page

  • Print layouts
  • Mobile UIs

3) Change page layout

  • If you had created page but you later on want to change to more suitable one... here's how you can do it

 

I hope you got the idea of this post. I know I could improve those samples a lot, but I just wanted to share my idea and give you the opportunity to make it much better than I did.

Anyways... happy hacking!

J

Comments (30)

Cancel reply

  1. koen says:

    Hello Janne,

    Thanks for that great article. But I’m still strugling with a couple of things :(. I inherited my page from the custom PublishingLayoutPageEx and it wend fine, All sharePoint words became in the right language exept the webparts?. All webparts stay in english despite what culture you using, is that normal? Or is a webparts rendered differently than the Page?

  2. Hi koen!

    Web parts don’t differ in that sense that if their made using resources, then they work fine.

    Here’s an example:

    writer.Write("Resource: " + HttpContext.GetGlobalResourceObject("Example","House").ToString() + "<br/>");

    If you add that to you web part then you get example same text than in your page.

    What is the exact web part your having problems with? It could be that it’s using XSL Style Sheets and there is hardcoded text. Is that web part your own or OOB web part?

    I hope my answer helped a little bit. Feel free to ping me if you didn’t get the idea.

    Anyways… Happy hacking!

    J

  3. Koen says:

    Hi janne,

    First of all, thanks for the quick response :).

    I’m not using a custom webpart. Instead I inserted a view of the common task list on the page and this view will always stay in english, nomatter what culture you set your thread to. Really strange.

    If you go and look at the structure of the task list (feature at C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12TEMPLATEFEATURESTasksListTasksSchema.xml) you can see it uses resources stored in C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12Resources.

    I have installed multiple language packs on my SHarepoint server so that every resource file is there in different language but for some strange reason it refuses to use it :).

    If I use variations, it will translate the tasklist in different languages but the problem is that I can use only one tasklist and that’s wy I used your solution.

  4. Hi Koen!

    Thanks for asking because it was really nice to dig on this one. I like to solve problems and this was definately a nice one πŸ™‚

    Okay.. I’ll explain what I did.

    1) I first verified your problem by creating same situation. And you’re absolutely right! Web Parts don’t actually change texts πŸ™

    2) Started digging with .resx files and DLLs with Reflector.

    3) Noticed that behind the scenes there is CoreResources class that handles translations. And if you look at the following code, does this ring a bell on you:

    static CoreResource()

    {

       _aIntl = Assembly.Load("Microsoft.SharePoint.intl, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c");

       _SPRM = new ResourceManager("Microsoft.SharePoint", _aIntl);

       _WebPartPageRM = new ResourceManager("Microsoft.SharePoint.WebPartPages.strings", _aIntl);

    }

    4) You start wondering why there is _WebPartPageRM (and is different from the other texts) and where are those text then.

    5) Take Reflector and open "Microsoft.SharePoint.intl, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c". Under it there is Resources and of course: Microsoft.SharePoint.WebPartPages.strings.resources.

    6) Search text that you know some web part page uses

    7) You have found the place for your text.

    Okay.. so now we have this "neutral" dll where are resources. But I don’t have access to systems that has multiple languages installed, so I don’t know that is that DLL available for different cultures.

    I hope that this gives you the answer your looking for… If you can dig your system too and you could give me feedback that you have verified my idea.

    Anyways… Happy hacking!

    J

  5. I just wanted to add a note for my previous comment: "Web Parts don’t actually change texts". But of course your own web parts change languages if you use resources πŸ™‚ Just to make this clear.

    J

  6. Koen says:

    Janne,

    You are right, I have found the CoreResource en the resource DLL’s.

    In a multilingual environment, you have a dll for each language:

    Microsoft.SharePoint.intl.dll –>

    Microsoft.SharePoint.resources

    Microsoft.SharePoint.WebPartPages.strings.resources

    microsoft.sharepoint.intl.resources.dll Language Dutch)  –>

    Microsoft.SharePoint.nl.resources

    Microsoft.SharePoint.WebPartPages.strings.nl.resources

    microsoft.sharepoint.intl.resources.dll Language French)  –>

    Microsoft.SharePoint.fr.resources

    Microsoft.SharePoint.WebPartPages.strings.fr.resources

    When I look at the resource string of a common task list, for instance the Priority field, you have following schema:

    <Field ID="{a8eb573e-9e11-481a-a8c9-1104a54b2fbd}"

       Type="Choice"

       Name="Priority"

       DisplayName="$Resources:core,Priority;"

       SourceID="http://schemas.microsoft.com/sharepoint/v3&quot;

       StaticName="Priority">

       <!– _locID@DisplayName="camlidT2" _locComment=" " –>

       <CHOICES>

         <CHOICE>$Resources:core,Priority_High;</CHOICE>

         <CHOICE>$Resources:core,Priority_Normal;</CHOICE>

         <CHOICE>$Resources:core,Priority_Low;</CHOICE>

       </CHOICES>

       <MAPPINGS>

         <MAPPING Value="1">$Resources:core,Priority_High;</MAPPING>

         <MAPPING Value="2">$Resources:core,Priority_Normal;</MAPPING>

         <MAPPING Value="3">$Resources:core,Priority_Low;</MAPPING>

       </MAPPINGS>

       <Default>$Resources:core,Priority_Normal;</Default>

    </Field>

    So, when I search for Priority_High, Priority_Normal, Priority_Low, I found nothing in the resource files.

    I can found it back in the resource file

    C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12Resourcescore.resx

    C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12Resourcescorecore.nl-nl.resx

    C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12Resourcescorecore.fr-fr.resx

    Also, I have seen that, like you said, there is a clear difference between plain SharePoint and a sharepoint WebPartPage

    internal static string GetString(CultureInfo culture, ResourceGroup rg, string name, params object[] values)

    {

       string text = null;

       StringBuilder builder;

       int num3;

       switch (rg)

       {

           case ResourceGroup.SharePoint:

               text = _SPRM.GetString(name, culture);

           case ResourceGroup.WebPartPage:

               text = _WebPartPageRM.GetString(name, culture);

           }

    So, I followed the trace from above in the listviewWebpart but so far I don’t see it yet.

    I keep you posted, I hope you will do it also

    Regards,

    Koen

  7. Andy H says:

    Hi Janne

    I’m having a few problems with this.  Firstly I’m at the point where it’s time to register in the GAC.  Is it possible to register this Class Library in the bin folder of the web application (site collection) rather than in the GAC?  I’ve tried placing the dll (which is strong named) into InetpubwwwrootwssVirtualDirectoriesMyAppbin folder and putting the entry in the web.config with the correct details (including the PublicKeyToken) but I get the Parser Error you show above still.

    We have been able to get our webparts working by doing the above.

    I thought I’d try registering it in the GAC on the server, but my first hurdle was that the gacutil was for version 1.1 only and would not accept it.  The admin control panels also only have the 1.1 .net configuration control panel.  Obviously .net 2 is on there (as SP is running) but I’ve double checked IIS which confirms it is using 2.0.

    I’ve copied up gacutil for 2.0 and it says it is registering it, but does not appear in the list (and I still get this parser error).   Any ideas?

    Preferably I’d like to get this class running from the web bin.

  8. Andy H says:

    I’ve been able to get it into the GAC now, but I release the error I am getting is different to the one on this page.  I get this error in all cases…

    Parser Error

    Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

    Parser Error Message: Could not load the assembly "…"

  9. Hi Andy!

    So now your’re having the "Could not load the assembly" error? I think you get the error because it’s not probably installed to the GAC. Did you use Visual Studio Command prompt and GACUTIL /i your_assembly_here? And did you verify that version number of gacutil is "Version 2.0.50727.42"? Or how did you install it to gac?

    Because if it’s installed to GAC properly and that "Inherits=…" part is also correctly set in page layout then this should be fine.

    Please give comment if that didn’t solve your problem.

    Anyways… happy hacking!

    J

  10. Andy H says:

    Hi Janne, the server I am installing to was missing the v 2.0.5… gacutil but I copied a version of it to the server and used:

    gacutil -i MyCompany.PublishingLayoutPageEx.dll

    which reported it was OK.  I did gacutil -l MyCompany.PublishingLayoutPageEx and it showed up.

    In my layout page (I made a copy of Article Left and modified that) I changed the top to read:

    <%@ Page language="C#" Inherits="MyCompany.PublishingLayoutPageEx,MyCompany,Version=1.0.0.0,Culture=neutral,PublicKeyToken=1294058909b4416a" %>

    The PublicKeyToken is correct (checked with Net Reflector).

    In VS2005 I have this:

    using System;

    using System.Collections.Generic;

    using System.Text;

    using System.Web.UI;

    using Microsoft.SharePoint.Publishing;

    using Microsoft.SharePoint;

    namespace MyCompany

    {

       public class PublishingLayoutPageEx : PublishingLayoutPage

       {

           public PublishingLayoutPageEx() : base()

           {

           }

       }

    }

    And I have added references to System.Web and the two sharepoint dll’s.

    My AssemblyInfo.cs properties show Assembly name: MyCompany.PublishingLayoutPageEx and Default namespace as MyCompany.

    I am new to both SharePoint and .NET but the instructions on your blog are clear enough and I’m not sure what I might be missing or doing wrong.  Even after an iisreset I get that error with "Could not load the assembly".

  11. Hi Andy!

    It seems that there is conflict with these two:

    MyCompany.PublishingLayoutPageEx.dll

    and

    Inherits="MyCompany.PublishingLayoutPageEx,MyCompany,Version=1.0.0.0,…

    I think the Inherits should be:

    MyCompany.PublishingLayoutPageEx,MyCompany.PublishingLayoutPageEx,…

    (just add ".PublishingLayoutPageEx")

    That looks like the problem… But you’re close the finish line already πŸ™‚

    Anyways.. happy hacking!

    J

  12. Andy H says:

    Thank you so much Janne

    I’m getting closer.  I’m now getting "Parser Error Message: Could not load type" so at least it is being recognised now and I can go back over my previous steps to check its all set up correctly.

  13. Andy H says:

    Got it more or less sorted now.  For information on my last problem, that was caused by an error in case (Mycompany v MyCompany).

    Thank you so much for the help, I wonder if I could ask one more question.  In SharePoint designer, the copy of ArticleLeft.aspx I created is stating "Master Page error   –   The page has controls that require a Master Page reference, but none is specified.  Attach a Master Page, or correct the problem in Code View."

    Attach a Master Page is a link but does not do anything and Code View is a link and highlights my <@ Page line at the top.

    I should add that currently my DLL sits in the sites bin folder and not the GAC as I originally wanted it just for my site collection and not anything else on the server, is the the problem or should I be looking elsewhere?

  14. Hi Andy!

    You can define the master page at the Page directive like this:

    … MasterPageFile="~/_layouts/default.master" …

    After that SPD should be fine with it.

    I think you can just deploy to your bin. I don’t see any problems with that.

    Anyways… happy hacking!

    J

  15. Myo Thaw Tun says:

    Dear Janne,

    I want to publish the News articles without text formatting.

    I mean I want to modify ArticleLeft.aspx PageLayout to display Left aligned image and text only.

    MOSS users can make news entries with Image on the left template.

    They may copy some news and texts from Internet and paste them into the content of news entry.

    But there would be text formatting at that entries. What I need to do is to display only Image with text without formatting.

    Is it possible to create new PageLayout to display like that? Can you give me some ideas how to do?

    Please kindly advice me. I hope your reply.

    Myo

  16. This is powerful stuff, and thanks to this I can do a lot more powerful MOSS WCM custom development.

  17. Kristian says:

    I was wondering if you had tried to do the masterpage change using a custom HttpModule? I have been trying to do it using the following code:

    public class Hook : IHttpModule

    {

       public void Init(HttpApplication context)

       {

           context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute);

       }

       void context_PreRequestHandlerExecute(object sender, EventArgs e)

       {

           Page page;

           IHttpHandler handler = HttpContext.Current.Handler;

           page = handler as Page;

           if (page != null)

               page.PreInit += new EventHandler(page_PreInit);

       }

       void page_PreInit(object sender, EventArgs e)

       {

           Page page = sender as Page;

           if (page != null)

           {

               string strUrl = "/Docs/_catalogs/masterpage/";

               SPWeb web = SPControl.GetContextSite(HttpContext.Current).OpenWeb();

               SPUser user = web.CurrentUser;

               if (user == null)

                   strUrl = "";

               else

                   strUrl += "BlueBand.master";

               if (strUrl.Length > 0)

                   page.MasterPageFile = strUrl;

           }

       }

       public void Dispose()

       {

       }

    }

    I works like a charm on wss 3.0, but MOSS publishing pages just ignores it. The preInit event hook is set on the page, but it is never called. I’m all out of ideas, any comments would be greatly appreciated.

  18. Martin says:

    Hello Janne,

    I am interested in the code to change the PageLayout associated with a PublishingPage.

    To my mind, the PublishingPage represents the data, and the PageLayout represents the view on that data.

    Consequently the view should be selectable dynamically.  I would expect to be able to place webparts on the PageLayout aspx page which connected to Field Values from the PublishingPage via FieldControls.  Thus the overall content displayed on a Publishing page would include PublishingPage columns, and adhoc data from else where, via connected web parts.  I would expect to control rights to the edit the web parts discretely from the rights to edit the columns of a PublishingPage via a PageLayout page (ie someone may be able to edit web parts, but not the PublishingPage data, and vice versa).

    However I have two concerns over whether I am off track with these thoughts:

    1) I not sure how to select the PageLayout dynamically at render time.  The closest I have got is to derive from the TemplateRedirectionPage, and set the PublishingPage.Layout property in it’s PreInit event (somehow).

    2) An article "How to Upgrade an Area based on a Custom Site Definition" at says "Webpart associations are also based on the actual publishing page"  I am not sure of the consequences of this.

    I would be very interested to have your response to this.

    Many Thanks

    Martin

  19. Faizur says:

    Kristian, did u find a solution to the problem? I am having the same issue

  20. I found a great article Janne Mattila. discuses that if the layout page just inherit from Microsoft.SharePoint.Publishing.PublishingLayoutPage…

  21. Egholm says:

    great article…..helped med a lot

  22. Mike says:

    namespace Microsoft.MCS.Common

     {

       public class PublishingLayoutPageEx : PublishingLayoutPage

       {

         public PublishingLayoutPageEx()

           : base()

         {

         }

       }

     }

    I am getting bellow error   " : base() " in this line

    Could not load file or assembly ‘Microsoft.SharePoint.Library, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c’ or one of its dependencies. The system cannot find the file specified.

  23. Mike says:

    PublishingLayoutPage vs. WebPartPage

    U cannot always inherit from PublishingLayoutPage,  If you are not using   Default. Master

    Read this article

    http://www.msdner.net/dev-archive/117/328-1202-1177874.shtm

  24. aaronnaas says:

    Thanks for the tip on PublishingLayoutPage changing the MasterPageFile on OnPreInit(). See how I changed it back in my Page scope OnPreInit() override.

  25. shareuser says:

    Thanks for this article. very helpful.

    Sorry, I have a basic question — where do i get the class library project template from? do you mean   any regular class? I am trying to understand, what would i need to start working on this.

    Thanks in advance!

  26. Overview The National Native Title Tribunal of Australia assists people to resolve native title issues

  27. i couldnt get your Print trick to work. For one, the page (either master page or page layout) says that there is no suitable method to override for OnPreInit so I tried Page_PreInit instead. This didnt work on the master page and while it executed on the page layout it did not change my master page. Is there an update call missing? did you test your code?

  28. oops – it works, I just didnt read the first half of the article and jumped to the code :-/ sorry!

  29. Sathya says:

    Hi,

         Please correct me if I am wrong.  What I under stand from above is that this would work for custom webparts but not for OOB webparts.  

Skip to main content