Loading...

Friday, August 5, 2011

WebEventReceivers on Publishing Custom Site Template

To Get the Publishing custom site template
type in browser   http://server:port/sites/publishingsite/_layouts/savetmpl.aspx
and save the template.

Prerequisites for Restoring Publishing Custom Site Template without errors
 1)Error for activating feature with specific guid
    If  you restore the Publishing template on  any other non-publishing site collection ,you will get the error for activating feature with specific guid.
To avoid this ,restore this site template in publishing site collection only.

Still if you are getting the error,
Open the WSP Package in Visual Studio 2010
Search for Onet.xml in the solution.
Ctrl+F Find the featureId for which you are getting error.
Activate it in Parent site collection and You are done.

2)Web Page not found error when subsite is created using publishing custom site template.
Write the event Web Event Receiver to set the welcome Page

public class EventReceiver1 : SPWebEventReceiver

{

public override void WebProvisioned(SPWebEventProperties properties)

{
base.WebProvisioned(properties);

SPWeb web = properties.Web;
if (properties.Web.MasterUrl.Contains("MasterPageNameofcustomTemplate") )

{

web.AllowUnsafeUpdates = true;

SPFolder rootFolder = web.RootFolder;

rootFolder.WelcomePage = "sitepages/customwelcomePage.aspx";

rootFolder.Update();

web.AllowUnsafeUpdates = false;

}

}

If you know the better approach to attach event receiver to particular site template only please add the comment

No comments: