One of the major shortcomings of SharePoint 2007 is that there is no easy way to display items from a list in another site collection. This is the kind of thing which is needed on a daily basis, in order for information to be centralized effectively and to avoid duplication.

I am currently developing a series of SharePoint templates, and I want training resources for these templates to be grouped in one central site collection. Each site created from one of the templates will need to pick up certain list information of training materials relevant for the template which has been used to create the site.

To meet this need, I decided to tackle this issue and find a solution. As a result, I found an approach (by Christophe at Path to SharePoint) which is a pure JavaScript solution and so can be configured through the Content Editor Web Part, making it available to power users. To use it, follow the steps below:

  1. Create a web part page and insert a Content Editor Web Part.
  2. Paste the following code into the Source Editor:
<!– Load and display list – iframe version –>

<!– Questions and comments: Christophe@PathToSharePoint.com –>

<DIV id=”ListPlaceholder”><IMG src=”/_layouts/images/GEARS_AN.GIF”></DIV>

<script type=”text/javascript”>

var mystring1 = “<iframe id=\”SourceList\” style=\”display:none;\” src=\””;

var mystring2 = “/sites/it-Outages”;

var mystring3 = “/lists/outages/sapoutages.aspx\” onload=\”DisplayThisList()\”></iframe>”;

document.write(mystring1+mystring2+mystring3);

</script>

<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(“onclick”);

allDescendants[i].removeAttribute(“onfocus”);

allDescendants[i].removeAttribute(“onmouseover”);

}

placeholder.innerHTML = displaylist.innerHTML;

}

</script>

  1. This example displays a list of SAP Outages from the IT-Outages site directly in a CDM Blog page. You will need to adapt the path according to your needs.

I will explain in a later blog post why it is useful to have variables available in the JavaScript file as shown above.

Advertisements