In this post we will see how to change the welcome page of a sharepoint site using object modelling.
Normally for any sharepoint site, the welcome page will be default.aspx. In this post we will set the Home.aspx page(present in pages library) as the welcome page, so that home.aspx will open as soon as user opens the site.
Below is the code snippet::
/// <summary>
/// method to add welcome page
/// </summary>
/// <param name="publishingWeb"></param>
/// <param name="oWeb"></param>
/// <param name="pageName"></param>
private void CreateWelcomePage(PublishingWeb publishingWeb, string pageName)
{
try
{
string fullPageUrl = publishingWeb.Url + "/Pages/" + pageName + ".aspx";
SPFile fileNew = publishingWeb.Web.GetFile(fullPageUrl);
publishingWeb.DefaultPage = fileNew;
fileNew.Publish(pageName + ".aspx set as Welcome Page");
fileNew.Approve(pageName + ".aspx set as Welcome Page");
publishingWeb.Update();
}
catch (Exception ex)
{
}
}
Call the above method as below
CreateWelcomePage(myPublishingWebObj,"Home");
Hope this helps...
Next post: Programatically applying master page in sharepoint
Normally for any sharepoint site, the welcome page will be default.aspx. In this post we will set the Home.aspx page(present in pages library) as the welcome page, so that home.aspx will open as soon as user opens the site.
Below is the code snippet::
/// <summary>
/// method to add welcome page
/// </summary>
/// <param name="publishingWeb"></param>
/// <param name="oWeb"></param>
/// <param name="pageName"></param>
private void CreateWelcomePage(PublishingWeb publishingWeb, string pageName)
{
try
{
string fullPageUrl = publishingWeb.Url + "/Pages/" + pageName + ".aspx";
SPFile fileNew = publishingWeb.Web.GetFile(fullPageUrl);
publishingWeb.DefaultPage = fileNew;
fileNew.Publish(pageName + ".aspx set as Welcome Page");
fileNew.Approve(pageName + ".aspx set as Welcome Page");
publishingWeb.Update();
}
catch (Exception ex)
{
}
}
Call the above method as below
CreateWelcomePage(myPublishingWebObj,"Home");
Hope this helps...
Next post: Programatically applying master page in sharepoint
No comments:
Post a Comment