It was easier than I thought.
- Wiki articles are just .ASPX pages in a wiki doc lib; you can address them directly by URL.
- The main article content is in a table with id="MSO_ContentTable". I discovered this by using IE8's F12 debugger and inspecting a wiki article's structure.
With this knowledge, it is fairly simple to craft a page that will load the articles. I used jQuery for this.
Here is the page I devised. This meets my needs:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Wiki Articles Report</title>
<!-- Note the relative path to the jQuery lib; it resides in the same doc lib as this page. -->
<script type="text/javascript" src="./jquery-1.6.1.min.js"></script>
<script type="text/javascript">
$(LoadArticles);
function LoadArticles() {
// Put the file names of the articles we want to process into an array
var values = ["Article1", "Article2", "Article3"];
// Process each article in the array
$.each(
values,
function (index, value) {
//Encode the URL to the article
var uri = encodeURI("http://myweb.com/sites/mysite/mywiki/" + value + ".aspx");
//Create a <div> to hold the article output
jQuery('<div/>',
{ id: value
}).appendTo('#Articles');
//Create a heading so we know which article is which
jQuery('<h1/>',
{ text: value
}).appendTo("#" + value);
//Create a sub-div to hold the article contents
jQuery('<div/>',
{ id: value + "Text"
}).appendTo("#" + value);
//Load the article's wiki content table element into the sub-div
$("#" + value + "Text").load(uri + " #MSO_ContentTable");
}
);
}
</script>
</head>
<body>
<h1>
Wiki articles report
</h1>
<div id="Articles"></div>
</body>
</html>
I saved this page to a HTML file (.HTM), stored the HTML file in a document library on the same site as the wiki, and finally uploaded jQuery script to the same doc lib (you can put it in a subfolder if you wish). I then run the HTML directly from the SharePoint site by simply clicking on it in the doc lib.
From here, I will copy-and-paste the page's output into a Word document and format as needed. Solution completed!
Some learnings:
- I had forgotten this but spaces are not a allowed in element ID properties! Well, it's been a while since I've done much front-end coding. :-)
- You can rename wiki article files through SharePoint "Edit Properties" dialog and SharePoint will update the links if referring files in the other wiki articles. I did not know that! It saved me a lot of editing time eliminating those pesky spaces in the file names!
- Debugging can be tricky. I did not have a good set of local test data so I was developed the page running against a server-based wiki. Cross-site scripting prevented the .load() command from pulling content when running the page locally. I had to upload the HTML file to the server doc lib repetitively and run it from there to get it to actually pull content. It was a little tedious, but not too bad.
Thanks and enjoy!