locked
customising my own properties to CEWP? RRS feed

  • Question

  • Hi,

    i am trying to set my own properties to Content Editor Webpart , can any one please help me in coding this
    Friday, August 5, 2011 3:25 AM

Answers

  • Hi,

     

    If you mean add new proprieties to content editor Webpart, you can create new class inherited from ContentEditorWebPart. Then add your code there. View this example: http://blog.mastykarz.nl/extending-content-query-web-part-xslt-custom-functions/

     

     

    If you need edit content editor Webpart proprieties from code, view following code:

     

    using (SPSite site = new SPSite("http://server:port"))
           {
             using (SPWeb web = site.OpenWeb())
             {
               using (SPLimitedWebPartManager manager = web.GetLimitedWebPartManager("pageurl", PersonalizationScope.Shared))
               {
                 foreach (System.Web.UI.WebControls.WebParts.WebPart webpart in manager.WebParts)
                 {
                   using (webpart)
                   {
                     if (webpart.GetType() == typeof(ContentEditorWebPart))
                     {
                       ContentEditorWebPart cewp = (ContentEditorWebPart)webpart;
    
                       XmlDocument xmlDoc = new XmlDocument();
                       XmlElement xmlElement = xmlDoc.CreateElement("HtmlContent");
                       xmlElement.InnerText = "<div>test</div>";
                       cewp.Content = xmlElement;
                       manager.SaveChanges(cewp);
                     }
                   }
                 }
               }
             }
           }

       

    Hope that helps a little

    Regards,

     


    Senior Sharepoint Developer,STS muawiyah.shannak@hotmail.com


    • Marked as answer by Qiao Wei Monday, August 15, 2011 1:15 AM
    Friday, August 5, 2011 2:31 PM