本文介绍了如何使用ssis从Sharepoint文档库下载文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用ssis从Sharepoint文档库下载文件?
how to download files from Sharepoint document library using ssis??
推荐答案
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Linq;
using System.Web.Services;
using System.Net;
using System.Configuration.Assemblies;
using System.IO;
using Microsoft.SharePoint;
namespace ST_6b5adaed5fa4406a9edde7de4ac8c259.csproj
{
[System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
#region VSTA generated code
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
#endregion
public void Main()
{
try
{
using (SPSite oSite = new SPSite("http://servername/sitename/"))
{
using (SPWeb oWeb = oSite.OpenWeb())
{
SPList list = oWeb.Lists["listname"];
SPListItemCollection oItemCol = list.GetItems();
foreach (SPListItem oItem in oItemCol)
{
string strID = Convert.ToString(oItem["ID"]);
SPFolder folder = oWeb.Folders["Lists"].SubFolders["Tasks"].SubFolders["Attachments"].SubFolders[strID];
foreach (SPFile file in folder.Files)
{
WebClient client1 = new WebClient();
client1.Credentials = System.Net.CredentialCache.DefaultCredentials;
FileStream outStream = new FileStream(@"C:\\destinationfolder\" + file.Name, FileMode.Create);
byte[] fileData = file.OpenBinary();
outStream.Write(fileData, 0, fileData.Count());
outStream.Close();
}
}
}
}
//});
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
Dts.TaskResult = (int)ScriptResults.Success;
}
}
}
已添加代码块。
[/编辑]
这篇关于如何使用ssis从Sharepoint文档库下载文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!