我有一个SharePoint列表,其中包含我想从SharePoint迁移到名为NewsArticle的Server数据库表中的新闻文章。该列表包括带有附件的项,这些附件需要进入使用NewsArticleAttachment的FILESTREAM表。
下面是我的SharePoint列表:
下面是我的Server数据库表:
NewsArticle IdTitleDescriptionCreated
NewsArticleAttachment IdNewsArticleFKNameUniqueID (统一标识符,行向导)File (var二进制(Max),FILESTREAM)
如何使用(SSIS)数据流任务来完成此任务?
发布于 2017-08-08 17:37:26
先决条件
对于数据流
Id列表的自然键从NewsArticle表中提取匹配的SharePoint列。对于NewsArticleFK列,我们将需要这个。在本例中,我们将使用Title列表的SharePoint列来匹配SQL表的Title列。
ID列表中选择SharePoint列,从NewsArticle表中选择Id列。
1. Go back to the "Script" tab and click the "Edit Script..." button. See the code below for details.
//This is referring to a Service Reference that will need to be created
using SC_be93317446654a518077a828ff747bd1.SharePointListsService;
using System;
using System.IO;
using System.Net;
using System.ServiceModel;
using System.Xml;public override void Input0_ProcessInputRow(Input0Buffer Row)
{
BasicHttpBinding listsSoapBinding = new BasicHttpBinding();
listsSoapBinding.Name = "ListsSoap";
listsSoapBinding.Security.Mode = BasicHttpSecurityMode.Transport;
listsSoapBinding.Security.Transport.ClientCredentialType =
HttpClientCredentialType.Ntlm;
EndpointAddress listsSoapAddress =
new EndpointAddress(Variables.SharePointListServiceUrl);
ListsSoapClient listsSoapClient =
new ListsSoapClient(listsSoapBinding, listsSoapAddress);
XmlElement attachmentCollection = listsSoapClient.GetAttachmentCollection(
Variables.SharePointListGuid, Row.ID.ToString());
foreach(XmlNode node in attachmentCollection.ChildNodes)
{
using (WebClient client = new WebClient())
{
AttachmentsBuffer.AddRow();
CredentialCache credentialCache = new CredentialCache();
credentialCache.Add(
new Uri(Variables.SharePointUrl),
"NTLM",
new NetworkCredential(
Variables.SharePointAccountUsername,
Variables.SharePointAccountPassword,
Variables.SharePointAccountDomain));
client.Credentials = credentialCache;
string attachmentUrl = node.InnerText;
byte[] data = client.DownloadData(attachmentUrl);
AttachmentsBuffer.AttachmentFile.AddBlobData(data);
AttachmentsBuffer.FileName = Path.GetFileName(node.InnerText);
AttachmentsBuffer.NewsArticleId = Row.NewsArticleId;
AttachmentsBuffer.UniqueID = Guid.NewGuid();
}
}
}下面是关于代码的一些需要注意的事情:
SharePoint_List_ServiceUrl变量相同。GetAttachmentCollection,从SharePoint中实际提取附件urls。WebClient从它们的urls下载附件。AddBlobData列上的AttachmentFile方法实际设置新列中的附件数据。https://stackoverflow.com/questions/45574732
复制相似问题