I have a SharePoint wiki with several separate articles that I would like to consolidate into a single MS Word document. The articles are in a standard SharePoint 2007 wiki with no customizations.

I would like to preserve as much of the HTML formatting as possible, so I want more than the raw text of the articles. I want the SharePoint formatting and appearance.

How can I collect the contents of the Wiki individual articles and merge them into a single MS Word document?

What tools should I use to accomplish this? Powershell scripts? JQuery? C# code? Other?

Note - The site is located at BPOS and I will never have admin access to the server. The publishing solution will not to run within SharePoint itself. It would have to run in Visual Studio, command line, PS IDE or some other external environment, whatever is appropriate. Also, third party publishing tools that install into SharePoint are not an option either.

Note 2 - the Word doc output does not need to be presentation ready. I just need to get the wiki content into the doc file by simplest means possible. Formatting can come later.

I am looking for any tips on getting started. Thanks!

  • Is this a one time thing or will this need to be repeated often? – Lori Jun 30 '11 at 14:31
  • More on the one-time side. It would be not a scheduled job or something that will be done routinely. It would be something I run periodically to consolidate the content of the wiki articles. – Wade Henderson Jun 30 '11 at 14:36
  • OK. I was thinking if it was just this one time, not going to be repeated, then copy and paste would be your very best bet. However, if you need to run it more than once, you may want to consider some other sort of option. – Lori Jun 30 '11 at 14:45

Since you are on a hosted 2007 environment server-side PowerShell and C# are out of consideration. Your best bet is to use jQuery to retrieve the Wiki article content via the lists.asmx Web service.

IIRC, there is a jQuery SharePoint Web service library on www.codeplex.com which could be helpful, but I never tried it myself.

  • Nice lib - I'll see if I can use it for this. +1 for the suggestion. – Wade Henderson Jul 1 '11 at 1:19
  • Wade: If you have any questions about SPServicex, post them in the Discussions on the Codeplex site and I'll try to help. M. – Marc D Anderson Jul 1 '11 at 2:29

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">
<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">


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
        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
                { id: value

            //Create a heading so we know which article is which
                { text: value
                }).appendTo("#" + value);

            //Create a sub-div to hold the article contents
                { id: value + "Text"
                }).appendTo("#" + value);

            //Load the article's wiki content table element into the sub-div
            $("#" + value + "Text").load(uri + " #MSO_ContentTable");




Wiki articles report

<div id="Articles"></div>


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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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