• Read data from a content editor webpart

    by  • June 11, 2010 • MOSS 2007 • 0 Comments

    In this article we will see how we can to get data from a content editor webpart from one page and display it in another page using a custom webpart.

    If you are new to webpart development you can check out my previous post about Hello world SharePoint Web Part for Beginners
    Add the following code in the RenderWebPartmethod of the webpart you are creating. The code and comments are self explanatory. Please pose a comment if you have any problem in understanding the code.

    SPSite site = new SPSite("http://mysite">http://mysite"); // create object of the site
    SPWeb web;
    Microsoft.SharePoint.WebPartPages.SPLimitedWebPartManager mgr = null;
    web = site.OpenWeb();
    mgr = web.GetLimitedWebPartManager("Pages/mypage.aspx", System.Web.UI.WebControls.WebParts.PersonalizationScope.User);//http://mysite/Pages/mypage.aspx will be the URL of the source page
    foreach (System.Web.UI.WebControls.WebParts.WebPart wp in mgr.WebParts)
    {
    if (wp.Title ==  "My RichTextEditor") //My RichTextEditor is the webpart title
    {
    SPWebPartPages.ContentEditorWebPart webPart =    (SPWebPartPages.ContentEditorWebPart)wp;
    output.Write(webPart.Content.InnerText);
    }
    }
    

    About

    Hojo Clement was working in US Technology in Trivandrum as a Senior Software Engineer. He has 6 years experience in working with Web Development Technologies inlcuding MOSS and ASP.net.

    Leave a Reply

    Your email address will not be published. Required fields are marked *