Summary: Learn to use code-behind files within master pages and page layouts that are used in Microsoft Office SharePoint Server (MOSS) 2007 Web content management (WCM) publishing sites.
Applies to: Microsoft Office SharePoint Server 2007, Microsoft Visual Studio 2005
Andrew Connell, Critical Path Training, LLC (Microsoft MVP)
January 2008
Wounderfull example.
I think I messed up. In the project I'm working on, I made a Module adding some Masterpages in the library through it. After deploying the solution the Masterpages and Page layouts now fails (shows error :
Value cannot be null.
Parameter name: uriString
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code).
When I click the link in Site Settings, it fails. But if I write the url straight into the URL bar in my browsers, it shows it perfectly.
I have no idea of why else this happened. My guess is that it's the Redirect.aspx page which is failing hard, but I have literally no idea of why this happened. on clicking Master page and page layouts link in the site settings page, URL is getting changed to SITE_COLLECTION_URL/_Layouts/RedirectPage.aspx?Target={SiteCollectionUrl}_catalogs/masterpage and showing the above mentioned error.Has anyone faced this issue beforehand? I googled a lot but could't find anything to help me out. If anyone have some idea about the same then it will be great help.
Regards,
Deepak Semwal
First of all thanks a lot for giving us information that we can use a code behind file with master page in moss.. i am in great need of that..
I am specifically having query related to code behind file for Master Page.. u have given example but havent made clear that where this master page with code behind file have to be linked with moss.. like where it had to deploy, where its dll file should be placed so that it can be used by a share point site.. please made it clear.. also the video demo is not working and the contet is not available for download.. PLEASE REPLY..
Thanks..
In order to get Design view working for a page layout you have to add a MasterPageFile declaration temporarily so it will let you edit content within asp:Content tags. You'll need to remove the MasterPageFile declaration before putting it into SharePoint, as even though SharePoint sets the MasterPageFile it seems to use your own if you put it in. You need to keep in the CodeBehind attribute so VS knows which .cs file to put the code into.
I'm using this for Page Layouts but i don't see why it wouldn't work for master pages as well, but you're less likely to need the coupled functionality for them.
I'm using WSPBuilder to create the WSP solution file from this project, which means all I have to do is have a feature.xml and it's related xml file in order to work on page layouts.
Hope this helps someone. Maybe i'll get a blog one day and set up a demo.
Andy
i follow the step by step , but why SharePoint Designer auto add the following code in my Page Template
it cause Exceptioin
<html xmlns:mso="urn:schemas-microsoft-com:office:office" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"><head><META name="WebPartPageExpansion" content="full">
<!--[if gte mso 9]><xml>
<mso:CustomDocumentProperties>
<mso:ContentTypeId msdt:dt="string">0x01010007FF3E057FA8AB4AA42FCB67B453FFC100E214EEE741181F4E9F7ACC43278EE81100530754E35E21CC44A05F9AF48B535E2F</mso:ContentTypeId>
</mso:CustomDocumentProperties>
</xml><![endif]-->
</head>
Still sorting through the details but PublishingPageLayout makes a FullTrust demand so running a custom cas policy probably won't work with this approach. WebPartPage doesn't make the same demand but I can't get it to work without FullTust either.
Michhes (http://blog.mediawhole.com)
Hi Andrew, thanks for the "encouragement" ...yes, it was in fact not too difficult to put the source code together following the concept of your VHT ;-)
there's one little glitch i encountered though ...when specifying the PublishingAssociatedContentType as ";#Article Page;#0x010100C...", as shown in the VHT, the pagelayout ends up not being associated properly with the "Page Layout Content Types" Content Type Group.
Instead, the following statement worked for me...
<Property Name ="PublishingAssociatedContentType" Value=";#$Resources:cmscore,contenttype_articlepage_name;;#0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D;#"/>
Thanks again for the great VHT!
jennifer www.finalcandidate.com
The only question I have is how absence of reference to PageLayoutTemplate class in ASP code helps to understand the concept?
jendxb-
I don't have the code available for download... but it should be pretty easy to throw it together folowing the VHT.
LRP13 & ChrisL-
It's no secret that the SharePoint development experience is lacking and MSFT is working to address that. So for how you can just decide to complain, or work to figure out how to address it to make it work the way you need it to work, as I demonstrated here in this VHT. Is it REALLY that hard to manually wire up a code behind with an ASPX? No... not at all. In fact, I'd argue it's a good exercise so people understand what the development tools do for them. Otherwise when stuff breaks, you don't know how to fix it.
Did we just enter some sort of time warp? One that takes us back to the ancient days before drag and drop, data binding, and point and click development? Surely this is indicative of programming in 1998 not 2008. I take that back. Coding in 1998 wasn't this complicated either.
