如何使用ssis从Sharepoint文档库下载文件? [英] how to download files from Sharepoint document library using ssis?

查看:166
本文介绍了如何使用ssis从Sharepoint文档库下载文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用ssis从Sharepoint文档库下载文件?

how to download files from Sharepoint document library using ssis??

推荐答案

看看这些是否有帮助:

MSDN博客:如何远程从SharePoint文档库下载文件 [ ^ ]

SharePoint:从远程客户端下载文档库文件 [ ^ ]
See if these help:
MSDN Blog: How to download files from a SharePoint document library remotely [^]
SharePoint: Download document Library file From Remote Client[^]


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文档库下载文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆