Friday, January 28, 2011

Display list items from one site collection to other site collection

Recently I had a request to display Calendar events from one site collection to other site collection. This way users do not need to readd the same events in both site collections.
I accomplish this I was thinking of web part or a workflow which will solve the process. But there is also another way to share with you.
This can be done by using IFrames, Javascript.Thanks to Christophe I got this code help from
http://blog.pathtosharepoint.com/2009/01/22/a-simple-method-to-display-a-list-in-another-site/

Check this code

Add a "Content Editor Web Part" on target site and copy this code below in "Source Editor"
Replace your source site (list url with view.aspx) in "Src". Click Apply and Click Ok. You are done.

<DIV id="ListPlaceholder"></DIV>
<!-- Paste the URL of the source list below: -->
<iframe id="SourceList" style="display:none;" src="http://SourceDomain.com/Lists/Calendar/calendar.aspx" onload="DisplayThisList()"></iframe>
<script type="text/javascript">
function DisplayThisList()
{
var placeholder = document.getElementById("ListPlaceholder");
var displaylist = null;
var sourcelist = document.getElementById("SourceList");
try {
   if(sourcelist.contentDocument)
      // Firefox, Opera
      {displaylist = sourcelist.contentDocument.getElementById("WebPartWPQ2") ;}
   else if(sourcelist.contentWindow)
      // Internet Explorer
      {displaylist = sourcelist.contentWindow.document.getElementById("WebPartWPQ2") ;}
   else if(sourcelist.document)
      // Others?
      {displaylist = sourcelist.document.getElementById("WebPartWPQ2") ;}
}
catch(err) { alert ("Loading failed");}
displaylist.removeChild(displaylist.getElementsByTagName("table")[0]);
var allDescendants = displaylist.getElementsByTagName("*");
for (i=0;i<allDescendants.length;i++) {
allDescendants[i].removeAttribute("id");
allDescendants[i].removeAttribute("onfocus");
allDescendants[i].removeAttribute("onmouseover");
}
placeholder.innerHTML = displaylist.innerHTML;
}
</script>

1 comment:

  1. We can use the same logic for other lists too, like Announcements, Custom lists etc.

    ReplyDelete