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;
                        }

                    }
                }
            });
       
 }


 

No comments:

Post a Comment

HTML

Script:

JS