Scenario: let’s say you have portal where content authors provision new pages on a regular basis; something like a news section on a site.
After a while you noticed that your content authors add specific types of web parts on all instances of a news-page; one thing you could do to make their life easier is to provision those web parts and any associated initial content automatically when new page gets created.
Let’s see how this is done in SharePoint Designer first, then how to transfer it to Visual Studio:
1. Open your site in SharePoint Designer 2010.
2. Open Page Layouts folder, and locate the page layout used by pages your users are creating.
If there are several of those, just repeat the steps for each page layout.
3. When the page has opened, locate a web part zone of your choice, you’ll see it defined as:
<WebPartPages:WebPartZone ... >
...
</WebPartPages:WebPartZone>
4. Insert the cursor into a chosen zone and use Insert -> WebPart from the ribbon to add a web part of your choice.
NOTE: out-of-the-box web part will have no problem being inserted here; but I had a problem inserting any custom web parts.
5. You will see the code in your designer looking like this (this is a content editor web part in my case):
<WebPartPages:ContentEditorWebPart runat="server" __MarkupType="xmlmarkup" WebPart="true" >
<WebPart xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/WebPart/v2">
<Title>Stuff</Title>
<FrameType>Default</FrameType>
<Description>Policy details content.</Description>
<IsIncluded>true</IsIncluded>
<ZoneID>MainZone1</ZoneID>
<PartOrder>2</PartOrder>
<FrameState>Normal</FrameState>
<Height />
<Width />
<AllowRemove>true</AllowRemove>
<AllowZoneChange>true</AllowZoneChange>
<AllowMinimize>true</AllowMinimize>
<AllowConnect>true</AllowConnect>
<AllowEdit>true</AllowEdit>
<AllowHide>true</AllowHide>
<IsVisible>true</IsVisible>
<DetailLink />
<HelpLink />
<HelpMode>Modeless</HelpMode>
<Dir>Default</Dir>
<PartImageSmall />
<MissingAssembly>Cannot import this Web Part.</MissingAssembly>
<PartImageLarge>/_layouts/images/mscontl.gif</PartImageLarge>
<IsIncludedFilter />
<ContentLink xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
<Content xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
<PartStorage xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
</WebPart>
</WebPartPages:ContentEditorWebPart>
6. Save the page layout and publish it if you like others to use it.
7. Now when you create a new page directly inheriting from this layout or change existing pages to this layout, you will get a web part inserted directly into the required zone.
Now, if you’re using Visual Studio solution and would like to do the same. Just repeat above steps with SharePoint Designer and copy the code you receive in step 5 into the page layout in your Visual Studio solution.
Same result will apply when you deploy your solution. For more tips and tricks like this one, check out my SharePoint developer book
Enjoy


