/// <summary> /// Delete a web part from a site based on the name. /// </summary> /// <param name="webPartName"></param> /// <returns></returns> public bool DeleteWebPart(string webPartName) { // Have to get all web parts from the page then iterate // through them all to find the title that matches. Once // we do that we get the Guid and delete it with another service bool rc = false; WebPartPagesWebService ws = NewWebPartPagesWebService(); string pageUrl = String.Concat(siteUrl, "/default.aspx"); try { XmlNode resultNode = ws.GetWebPartProperties(pageUrl, Storage.Shared); foreach (XmlNode node in resultNode) { string partTitle = node["Title"].InnerText; if (partTitle.ToUpper() == webPartName.ToUpper()) { string partId = node.Attributes["ID"].InnerText; Guid storageKey = new Guid(partId); ws.DeleteWebPart(pageUrl, storageKey, Storage.Shared); rc = true; } } } catch (SoapException ex) { Console.WriteLine(ex.Message); } return(rc); }