Louis-Charles Gagnon

Microsoft Azure, Office 365 and SharePoint Blog

How to remove "Get Started with your site" from a Team Site - Sharepoint 2013/Online

When you create a new team site on SharePoint 2013 and SharePoint Online, you are presented with a default "welcome" webpart: 


In order to remove this webpart, you may use the client context with the following code:            

Using SharePoint Dll:

          var web = clientContext.Web;
          clientContext.Load(web);

var web = clientContext.Web;

var file = web.GetFileByServerRelativeUrl(web.ServerRelativeUrl + "/SitePages/Home.aspx");

var wpm = file.GetLimitedWebPartManager(PersonalizationScope.Shared);

web.Context.Load(wpm.WebParts, wps => wps.Include(wp => wp.WebPart.Title));

web.Context.ExecuteQueryRetry();


for(var i=0;i<wpm.WebParts.Count;i++)

{

    if (wpm.WebParts[i].WebPart.Title.Equals("Get started with your site"))

    {

        wpm.WebParts[i].DeleteWebPart();

        web.Context.ExecuteQueryRetry();

    }

}




            var web = clientContext.Web;
            clientContext.Load(web);
            web.Context.ExecuteQuery();
            web.DeleteWebPart(web.ServerRelativeUrl + "/SitePages/Home.aspx", "Get started with your site");
            web.Context.ExecuteQuery();

In order to change the default homepage of a team site, here is the code:

            var web = clientContext.Web;
            var rootFolder = web.RootFolder;
            clientContext.Load(web);
            clientContext.Load(rootFolder);
            rootFolder.WelcomePage = "/SitePages/MyHomePage.aspx";
            rootFolder.Update();
            clientContext.ExecuteQuery();


blog comments powered by Disqus