Sunday, March 25, 2012

Saturday, March 24, 2012

Set Default page for the all Sites/Subsite of the Site collection.

Set Default Page for All sites inside the Sitecollection



public static void SetPageAsDefult()
        {

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {


                string strUrl = "http://MYSITE:1000/sites/project/";

                using (SPSite oSiteCollection = new SPSite(strUrl))
                {
                    string sitecollection = oSiteCollection.RootWeb.Title;
                    if (oSiteCollection != null)
                    {
                        foreach (SPWeb web in oSiteCollection.AllWebs)
                        {

                            SPFolder rootFolder = web.RootFolder;
                            rootFolder.WelcomePage = "pages/Home.aspx";
                            web.AllowUnsafeUpdates = true;
                            rootFolder.Update();
                            web.AllowUnsafeUpdates = false;
                        }

                    }
                }
            });
       
 }


 

Set Master page for Publishing sites for publishing page

Change master page for Publlishing site .


SPSite curSite = new SPSite(http://MySERVER:1000/); 
SPWeb objweb = curSite.OpenWeb(strWeb);
//Besure to check the path of the master page.

Uri masterUri = new Uri("http://MySERVER:1000/" + /_catalogs/masterpage/My_MasterPage_Blank_right_1.0.master");


objweb.CustomMasterUrl = masterUri.AbsolutePath;
objweb.AllowUnsafeUpdates = true;

objweb.Update();

objweb.AllowUnsafeUpdates = false;

HTML

Script:

JS