在 SharePoint 2013 中实用地如何将文档库项目从一个网站集复制到另一个网站集
In SharePoint 2013 pragmatically how to copy document Library Item from one site collection to another site collection
我有 2 个与 site1 和 site2 相同的 Web 应用程序的网站集。
我在两个站点上都创建了文档库,因为 Doc1 和 Doc2.when 项目在 Documemnt 库中上传,然后将该项目复制到 site2 Doc2 库中。
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
namespace CopyListItems
{
class Program
{
static void Main(string[] args)
{
try
{
SPSite mySourceSite = new SPSite("http://fivenumber:5/");
SPWeb mySourceWeb = mySourceSite.OpenWeb();
SPList mySourceList = mySourceWeb.Lists["Source List"];
SPQuery mySourceListQuery = new SPQuery();
mySourceListQuery.Query = "" +
"" +
"" +
"" +
"";
SPListItemCollection mySourceItemColl = mySourceList.GetItems(mySourceListQuery);
int count = 0;
foreach (SPListItem mySourceListItem in mySourceItemColl)
{
string SourceEmpId = mySourceListItem["Employee Id"].ToString();
string SourceEmpName = mySourceListItem["Employee Name"].ToString();
string SourceDesig = mySourceListItem["Designation"].ToString();
string SourceAge = mySourceListItem["Age"].ToString();
SPSite myDestinationSite = new SPSite("http://fivenumber:50");
SPWeb myDestinationWeb = myDestinationSite.OpenWeb();
SPList myDestinationList = myDestinationWeb.Lists["Destination List"];
SPListItem myDestinationListItem = myDestinationList.Items.Add();
myDestinationListItem["Employee Id"] = SourceEmpId;
myDestinationListItem["Employee Name"] = SourceEmpName;
myDestinationListItem["Designation"] = SourceDesig;
myDestinationListItem["Age"] = SourceAge;
myDestinationWeb.AllowUnsafeUpdates = true;
myDestinationListItem.Update();
myDestinationWeb.AllowUnsafeUpdates = false;
count++;
Console.WriteLine(count+" item(s) copied");
}
Console.WriteLine("Press enter to continue");
Console.ReadLine();
}
catch (Exception ex)
{
Console.Write(ex);
Console.WriteLine("Press enter to continue");
Console.ReadLine();
}
}
}
}
我有 2 个与 site1 和 site2 相同的 Web 应用程序的网站集。 我在两个站点上都创建了文档库,因为 Doc1 和 Doc2.when 项目在 Documemnt 库中上传,然后将该项目复制到 site2 Doc2 库中。
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
namespace CopyListItems
{
class Program
{
static void Main(string[] args)
{
try
{
SPSite mySourceSite = new SPSite("http://fivenumber:5/");
SPWeb mySourceWeb = mySourceSite.OpenWeb();
SPList mySourceList = mySourceWeb.Lists["Source List"];
SPQuery mySourceListQuery = new SPQuery();
mySourceListQuery.Query = "" +
"" +
"" +
"" +
"";
SPListItemCollection mySourceItemColl = mySourceList.GetItems(mySourceListQuery);
int count = 0;
foreach (SPListItem mySourceListItem in mySourceItemColl)
{
string SourceEmpId = mySourceListItem["Employee Id"].ToString();
string SourceEmpName = mySourceListItem["Employee Name"].ToString();
string SourceDesig = mySourceListItem["Designation"].ToString();
string SourceAge = mySourceListItem["Age"].ToString();
SPSite myDestinationSite = new SPSite("http://fivenumber:50");
SPWeb myDestinationWeb = myDestinationSite.OpenWeb();
SPList myDestinationList = myDestinationWeb.Lists["Destination List"];
SPListItem myDestinationListItem = myDestinationList.Items.Add();
myDestinationListItem["Employee Id"] = SourceEmpId;
myDestinationListItem["Employee Name"] = SourceEmpName;
myDestinationListItem["Designation"] = SourceDesig;
myDestinationListItem["Age"] = SourceAge;
myDestinationWeb.AllowUnsafeUpdates = true;
myDestinationListItem.Update();
myDestinationWeb.AllowUnsafeUpdates = false;
count++;
Console.WriteLine(count+" item(s) copied");
}
Console.WriteLine("Press enter to continue");
Console.ReadLine();
}
catch (Exception ex)
{
Console.Write(ex);
Console.WriteLine("Press enter to continue");
Console.ReadLine();
}
}
}
}