Set default page for SharePoint publishing site

Here is a function that will set the default page for a publishing site.

Just pass in your web and the new default page name, it will take care of the rest.
Works great when creating new sites.

public static void SetPageAsDefault(SPWeb web, String pageName)

if (PublishingWeb.IsPublishingWeb(web))

PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web);

SPFile welcomefile = web.GetFile(pageName);
if (null != welcomefile)
publishingWeb.DefaultPage = welcomefile;


Got something to add?

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s