I had an interesting problem recently with a Site Definition. I was trying to create a publishing page, which would not create as the correct content type. I still haven’t got to the bottom of why.
However, time was limited, and we were going to have to create a feature receiver to staple to our site definition anyway, so I had a look at creating a publishing page programmatically.
We needed a feature receiver as the customer wanted the home page of their site to have a ‘Search Box’ which would ‘Search this site’, but go to a custom results page in a Search Center. My plan was to use a Search Box Web part, configured to go to a custom results page, and to append the query term:
site: [url to site]
e.g. site:http://sharepoint/finance/
Naturally, you don’t know the URL of the site until the site has been created – so this web part would have to be created programmatically. Continue reading “Programmatically create pages – and Add Web Parts”





