Wednesday, June 29, 2011

Deploy Welcome Page in Team Sites-continuation

Code for the buttons are Part1

protected void Page_Load(object sender, EventArgs e) {
if (!Page.IsPostBack) {
if (txtWelcomePage != null) {
using (SPSite siteCollection = new SPSite(SPContext.Current.Web.Url))
{
using (SPWeb site = siteCollection.OpenWeb())
{
txtWelcomePage.Text = site.RootFolder.WelcomePage;
}
}
}
}
}
protected void ButtonOkUpdatePageClick(object sender, EventArgs e) {
if (!string.IsNullOrEmpty(txtWelcomePage.Text)) {
using (SPSite siteCollection = new SPSite(SPContext.Current.Web.Url))
{
using (SPWeb site = siteCollection.OpenWeb())
{
SPFolder rootFolder = site.RootFolder;
rootFolder.WelcomePage = txtWelcomePage.Text;
rootFolder.Update();
SPNavigationNode homeNode = site.Navigation.TopNavigationBar.Navigation.Home;

//This is to update the default navigation
homeNode.Url = SPUrlUtility.CombineUrl(site.Url, txtWelcomePage.Text);
homeNode.Update();

Response.Redirect(SPUrlUtility.CombineUrl(site.Url, "/_layouts/settings.aspx"));
}
}
}
}
protected void ButtonCancelUpdatePageClick(object sender, EventArgs e) {
// redirect to the site's settings page
Response.Redirect(SPUrlUtility.CombineUrl(SPContext.Current.Web.Url, "/_layouts/settings.aspx"));
}
And Coming to the Limitations as you might have seen there is no option to roll back the new Home Page to the default.aspx.So Here Comes the Method3 which gives us that control.

No comments:

Post a Comment