Migrating Wiki Pages Remotely – Part 03

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

I wrote before about how you could use lists.asmx to get the data out of a Wiki Library just like any other list type. There is one significant difference though that may not be immediately apparent. If you investigate the internal structure of a Wiki Page, you will find that we do store a file object—but it is an empty stub object. It doesn’t contain the actual data or body of the Wiki. The body or content of the Wiki Page is stored within a metadata property called ows_MetaInfo. The ows_MetaInfo field is a huge propertybag that you ideally would want to use a RegEx to parse and look for data within. It is not something you can simply split and read because each separator is different. While this is something you could absolutely code around, fortunately, there is a shortcut for the Wiki content itself called WikiField. This will make it much easier for you to get the source data from the source server without having to handle the parsing and various different scenarios that could happen within ows_MetaInfo. Here I will show you how I connected up to a source lists.asmx and copy.asmx and got the WikiField value versus getting the ows_MetaInfo.

First I’ll show getting it WikiField with copy.asmx. I’m using lists.asmx to get a list of files in the Library.

if ((txt_SelectedWiki.Text.Length > 0) && (txt_SelectedWiki2.Text.Length > 0))

{

    Server1WS.Lists s1L = new WikiMigrator.Server1WS.Lists();

    s1L.Url = txt_SiteName.Text.Trim().TrimEnd("/".ToCharArray()) + "/_vti_bin/lists.asmx";
// Always set credentials on your webservice

    s1L.Credentials = System.Net.CredentialCache.DefaultCredentials;

    try

    {

        // Need to provide a large number or we will restrict at the default 100 items if null

        XmlNode ndListItems = s1L.GetListItems(txt_SelectedWiki.Text, null, null, null, txtNumberRows.Text, null, null);

        XmlNode ndListItemDetail = ndListItems.ChildNodes[1];

        foreach (XmlNode item in ndListItemDetail.ChildNodes)

        {

            try // This is in a try/catch block so that we silently skip anything that isn’t valid

            {

                if (item.Attributes != null)

                {

                    // ows_LinkFilename was the most obvious attribute for identifying Wikis page names, you might choose a different field and parse it if you are handling other list types

                    string itemName = item.Attributes["ows_LinkFilename"].Value;

                    // I put this trace before the if so I would see it in the log

                    Trace.WriteLine("Copying: " + itemName);

                    if (!string.IsNullOrEmpty(itemName))

                    {

                        Server1CopyWS.Copy myCopyService = new WikiMigrator.Server1CopyWS.Copy();

                        myCopyService.Url = txt_SiteName.Text.Trim().TrimEnd("/".ToCharArray()) + "/_vti_bin/copy.asmx";

                        myCopyService.Credentials = System.Net.CredentialCache.DefaultCredentials;

                        string copySource = txt_SiteName.Text + "/" + txt_SelectedWiki.Text + "/" + itemName;

                        WikiMigrator.Server1CopyWS.FieldInformation myFieldInfo = new WikiMigrator.Server1CopyWS.FieldInformation();

                        WikiMigrator.Server1CopyWS.FieldInformation[] myFieldInfoArray = { myFieldInfo };

                        byte[] myByteArray;

                        uint myGetUint = myCopyService.GetItem(copySource, out myFieldInfoArray, out myByteArray);

                        string sourceWikiField = string.Empty;

                        for (int x = 0; x < myFieldInfoArray.Length; x++)

                        {

                            if (myFieldInfoArray[x].InternalName == "WikiField")

                            {

                                sourceWikiField = myFieldInfoArray[x].Value;

                            }

                            if (chkDebugFull.Checked)

                            {

                                Trace.WriteLine("SourceProp: " + myFieldInfoArray[x].InternalName + " = " + myFieldInfoArray[x].Value);

                            }

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