0

我正在将图像文件从网站的文档库移动到另一个网站的文档库。我收到以下错误@ line SPListItem oListItemDest = oFileDest.Item;

错误:[Microsoft.SharePoint.SPException] = {“指定的对象不属于列表。”}

代码:

   try
   {
      using (SPSite oSiteCollectionSrc = new SPSite("http://dev:32223/"))
      {
                SPWeb oWebsiteSrc = oSiteCollectionSrc.AllWebs["en/people"];
                SPList oListSrc = oWebsiteSrc.Lists["Images"];  

                SPListItemCollection collListItemsSrc = oListSrc.Items;

                foreach (SPListItem oListItemSrc in collListItemsSrc)
                {
                    SPFile oFileSrc = oListItemSrc.File;
                    Stream srcStream = oFileSrc.OpenBinaryStream();

                    using (SPSite oSiteCollectionDest = new SPSite("http://www.devmysites.com/"))
                    {
                        SPWeb oWebsiteDest = oSiteCollectionDest.OpenWeb("en/people");
                        SPList oListDest = oWebsiteDest.Lists["Images"];

                        SPFileCollection collFilesDest = oListDest.RootFolder.Files;

                        try
                        {

                            SPFile oFileDest = collFilesDest.Add(oListDest + @"/" + oFileSrc.Name, srcStream, true);
                            SPListItem oListItemDest = oFileDest.Item;
                            oListItemDest["Created"] = oFileDest.TimeCreated;
                            oListItemDest["Modified"] = oFileDest.TimeLastModified;
                            oListItemDest.Update();
                        }
                        catch(Exception es1)
                        {
                            Console.WriteLine("# Exception:#");
                            Console.WriteLine(es1.Message);
                        }

                        oWebsiteDest.Dispose();
                    }
                }
                oWebsiteSrc.Dispose();
            }
        }
        catch (Exception es)
        {
            Console.WriteLine("# Exception:#");
            Console.WriteLine(es.Message);
        }
4

1 回答 1

0

我还不得不在共享点列表之间复制文档,我曾经这样做的代码在这个问题的答案中:SharePoint 2010:在列表之间复制文档

于 2012-11-23T23:49:33.297 回答