Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

How do you access a webpart that lives on a page in a different site? For example, I have http://foo.com/ and http://foo.com/blog. How can I access a webpart on the blog site from the foo.com site?

share|improve this question
    
I'm not sure what you mean here. The web part, if it is custom, should be deployed as a feature and you should be able to use it, however, I think you may be referring to a list or library that you want to show on the top level site? –  Lori Sep 8 '11 at 15:31
    
I am creating a visual webpart and adding it to the top level site. This webpart needs to get information that lives in a webpart in the blog site. I hope that makes sense. Not sure how to accomplish this. Thanks for the help. –  obautista Sep 8 '11 at 15:42
1  
I'm not sure how you would access data that lives in a web part, it should live in a list or library and be displayed in a web part in order to be re-used throughout the site colleciton. –  Lori Sep 8 '11 at 15:57
    
So I cannot access data in a content editor webpart from a different webpart? Not sure if this is possible. –  obautista Sep 8 '11 at 16:04
    
No, not from a content editor web part. The data has to exist somewhere like a list or library and be displayed in a web part, then it can be accessed in another site in the site collection –  Lori Sep 8 '11 at 16:06

3 Answers 3

Here is my suggestion based on the comments/discussion. Create a list in the blog site collection and put the information in that list in that location. Next, add a web part to the page where you currently have your CEWP that is a view of the list, then you can customize the view of the list to show only the data you want to show and customize how it is displayed.

Once you have this done, you can go to the upper level site and use the Content Query Web Part (CQWP) and have it query this same list. You can customize the CQWP as well to display the information in the manner you prefer.

Another option is to use a Data View Web Part (DVWP) which is also highly customizable. You can do this from SharePoint Designer.

share|improve this answer
    
I think he/she really means to access the Web Part, not the content. –  Christophe Sep 8 '11 at 19:08
up vote 0 down vote accepted

After a couple hours of monkeying with it - the below works. This code is in a visual webpart. I am able to get content editor webpart properties from a different site like this.

using (Microsoft.SharePoint.SPSite site = new Microsoft.SharePoint.SPSite("http://www.foo.com/blogs/person"))
{
   using (Microsoft.SharePoint.SPWeb web = site.OpenWeb())
   {
       Microsoft.SharePoint.SPFile file = web.GetFile("/blogs/person/default.aspx"); 
       Microsoft.SharePoint.WebPartPages.SPLimitedWebPartManager manager = file.GetLimitedWebPartManager(PersonalizationScope.Shared);
       Microsoft.SharePoint.WebPartPages.SPLimitedWebPartCollection webParts = manager.WebParts;
       WebPart wp = webParts["<id, index or guid>"];

       //if needed - add code to update webpart
       //manager.SaveChanges(wp);
   }
}
share|improve this answer

SharePoint comes with Web Services, which would be another option to access a Web Part, and would work across sites. Check out the GetWebPart2 and SaveWebPart2 methods:

http://msdn.microsoft.com/en-us/library/websvcwebpartpages.webpartpageswebservice.getwebpart2.aspx

http://msdn.microsoft.com/en-us/library/websvcwebpartpages.webpartpageswebservice.savewebpart2.aspx

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.