Read data from a content editor webpart

Jun 11 2010 Published by Hojo Clement under MOSS 2007, Webpart

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);
}
}
Share :
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DotNetKicks
  • email
  • Twitter

Related posts

No responses yet

Leave a Reply