Wednesday, 27 June 2012

Clear Team Site home.aspx by c# code

Here's how you clear the home.aspx page of a default Team Site programmatically
        public void clearContentOnMain()
        {
            try
            {
                using (SPSite site = new SPSite(TEAMSITEURL))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        SPFile homePage = web.GetFile("SitePages/Home.aspx");
                        if (homePage.Exists)
                        {
                            homePage.Item[SPBuiltInFieldId.WikiField] = "";
                            homePage.Item.Update();

                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new SPException("Error getting SitePages/Home.aspx " + ex.ToString());
            }

        }

No comments:

Post a Comment