次の方法で共有


Migrating Wiki Pages Remotely – Part 07

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

Now let us consider the next potential problem in using copy.asmx. There were some instances where I found that the copy.asmx would fail outright. One of these was when I would go between significant schema versions. In my case, I was going between a very early version of o14 and SharePoint 2007. The problem here was that copy.asmx grabs a binary copy of the current object which has all of the information embedded in it. This was a problem because I didn’t have the o14 assemblies (14.x.x.x instead of 12.x.x.x) on my destination server. I will preface the rest of this commentary with the thought that by the time we launch o14, this may not be a problem at all (no promises on what will or won't be in o14 will be comming from this blog--sorry). However, my approach in dealing with the problem is still valuable to share, and that is why I decided to put it here. Here is how I dealt with it: Going back to the initial code where we successfully got the data from the source server’s list.asmx, I did that again. However, for this special case scenario, I decided it was appropriate to make the destination a local OM destination. Then I could run the tool again and go web service to web service form my local server over to my actual destination. Yes, this is an extra set—but it still allowed me to not have to have access to either of the production servers locally. This code path is triggered in my code by the DestLocal checkbox. Here’s what that code looks like:

private bool manualLocalCopy(string sourceWikiField, string itemName, WikiMigrator.Server2CopyWS.FieldInformation[] myFieldInfoArray2, byte[] myByteArray, string[] copyDest, bool copySuccess)

{

    bool manualSuccess = false;

    if (!string.IsNullOrEmpty(sourceWikiField))

    {

        try

        {

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

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

                // You need a try-catch block because new SPSite(), OpenWeb(), and GetList() all throw on failure.

            try

            {

                // open site, web, list, and file collection

                SPSite site = new SPSite(txt_SiteName2.Text);

                SPWeb web = site.OpenWeb();

                SPList list = web.Lists[txt_SelectedWiki2.Text];

                SPFileCollection files = list.RootFolder.Files;

                SPFile newFile = null;

                try

                {

                    // add new wiki page

                    newFile = files.Add(txt_SelectedWiki2.Text.TrimEnd("/".ToCharArray()) + "/" + itemName, SPTemplateFileType.WikiPage);

                }

                catch (Exception exc)

   {

                    newFile = files[itemName];

                }

                // get the list item corresponding to the wiki page and update its content

                SPListItem item = newFile.Item;

                item["WikiField"] = sourceWikiField;

                item.Update();

                manualSuccess = true;

                copySuccess = true;

            }

            catch (Exception exc)

            {

                if (exc.Message.Contains("-2147024816"))

                {

                    Trace.WriteLine("File exists in target");

                }

                else

                {

                    Trace.WriteLine("manualLocalCopy Exception: " + exc.Message);

                }

            }

        }

        catch (Exception exc)

        {

            Trace.WriteLine("***ERROR*** Manual copy failed " + exc.Message);

        }

    }

    if (!manualSuccess)

    {

        Trace.WriteLine("Manual copy of " + itemName + " failed.");

        txt_Status.Text += "Manual copy of " + itemName + " failed.\r\n";

  txt_Status.Select(txt_Status.Text.Length, 0);

        txt_Status.ScrollToCaret();

    }

    else

    {

        Trace.WriteLine("Coppied to " + txt_SiteName2.Text.TrimEnd("/".ToCharArray()) + "/" + txt_SelectedWiki2.Text.TrimEnd("/".ToCharArray()) + "/" + itemName);

        txt_Status.Text += "Coppied to " + txt_SiteName2.Text.TrimEnd("/".ToCharArray()) + "/" + txt_SelectedWiki2.Text.TrimEnd("/".ToCharArray()) + "/" + itemName + "\r\n";

        txt_Status.Select(txt_Status.Text.Length, 0);

        txt_Status.ScrollToCaret();

        copySuccess = true;

    }

    return copySuccess;

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

Comments