Beispiel #1
0
        /// <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);
        }
Beispiel #2
0
        /// <summary>
        /// News the web part pages web service.
        /// </summary>
        /// <returns></returns>
        public WebPartPagesWebService NewWebPartPagesWebService()
        {
            WebPartPagesWebService ws = new WebPartPagesWebService();

            ws.Url         = siteUrl + "WebPartPages.asmx";
            ws.Credentials = Credentials;
            return(ws);
        }
Beispiel #3
0
        /// <summary>
        /// Adds a web part from XML to the current site. This
        /// dynamically configures the webs web service based
        /// on the site url and hides any web services we call
        /// from the client.
        /// </summary>
        /// <param name="webPartXml">The XML representation of
        /// a web part. This can be loaded up from .dwp file from
        /// a client calling it.</param>
        public bool AddWebPart(string webPartXml)
        {
            bool rc = false;
            WebPartPagesWebService ws = NewWebPartPagesWebService();
            string pageUrl            = String.Concat(siteUrl, "/default.aspx");

            try
            {
                ws.AddWebPart(pageUrl, webPartXml, Storage.Shared);
                rc = true;
            }
            catch (SoapException sex)
            {
                Console.WriteLine(sex.Message);
            }
            return(rc);
        }