Migrating Wiki Pages Remotely – Part 09

Note, this series starts at blogs.msdn.com/dwinter/archive/2008/06/28/migrating-wiki-pages-remotely-part-01.aspx

One of the final touches was to take care of the “but this data here is out of place”, or “this string still has the old server”, etc type complaints. You may have noticed this, but I wanted to point it out separately (since this works out to be a fall back plan in the code). When I do the link fix-up button (yet another reason for separating the operations into two different buttons), I looked to see if the Adv Repl (advanced replace) was checked and processed those values—in case you missed it, it was here:

if (chk_AdvRepl.Checked)

{

    modifiedData = modifiedData.Replace(txt_Repl1.Text, txt_Repl2.Text);

}

This was significant because it allows the admin to have a search and replace style tweak. Ideally this kind of code should never be placed in the hands of an end user—but if you polished it up a bit, it could become an effective tool in allowing folks to make bulk search/replace type changes across wikis. Dangerous—but hey, that’s up to the implementer to control (that’s you! J).

Another thing that may be of interest was the:

// Kill the linefeeds and \\ because they will be literal since we have to use CDATA.

modifiedData = modifiedData.Replace(@"\r\n", "");

I found that when built up the CDATA for use in UpdateListItems from lists.asmx here:

string strBatch = "<Method ID='1' Cmd='Update'>" +

    "<Field Name='ID'>" + item.Attributes["ows_ID"].Value + "</Field>" +

    "<Field Name='WikiField'><![CDATA[" + modifiedData + "]]></Field>" +

    "<Field Name='_CopySource'></Field></Method>";

That the call to UpdateListItems would suceed, but I would have massive numbers of \r\n littered throughout the wiki pages. The replace I was doing there was to counter that and could possibly be destructive, but generally, I did not find it to be.

Well that’s all of my thoughts for now. I hope this wasn’t too excessively long. It is a new style for me that I wanted to try out—if it is well received I will try it again sometime. If you’d prefer smaller nuggets—I can try for that to. I am open to suggestions.

Thanks for reading! You can find the information about the source in Part 10.

Part 10:
blogs.msdn.com/dwinter/archive/2008/06/28/migrating-wiki-pages-remotely-part-10.aspx