Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用SSIS(vb.net/C#.net)将压缩文件上载到SharePoint文档库Office 365_C#_Vb.net_Sharepoint_Ssis_Office365 - Fatal编程技术网

使用SSIS(vb.net/C#.net)将压缩文件上载到SharePoint文档库Office 365

使用SSIS(vb.net/C#.net)将压缩文件上载到SharePoint文档库Office 365,c#,vb.net,sharepoint,ssis,office365,C#,Vb.net,Sharepoint,Ssis,Office365,我需要将压缩文件从本地文件夹上载到SharePoint文档库。我无法使用WebClient PUT方法将此上载到Office 365 SharePoint网站。请使用C#或VB.net共享代码,因为我需要在SSIS包中实现此功能。根据您对SharePoint服务器的访问权限,有两个可用选项。请看以下内容: 文件类型并不重要,但您可能还需要将签入/签出流程与SharePoint合并。您需要收集此过程的其他详细信息,最好与SharePoint管理员联系以获取更多信息。我们可以使用脚本任务上载。

我需要将压缩文件从本地文件夹上载到SharePoint文档库。我无法使用WebClient PUT方法将此上载到Office 365 SharePoint网站。请使用C#或VB.net共享代码,因为我需要在SSIS包中实现此功能。

根据您对SharePoint服务器的访问权限,有两个可用选项。请看以下内容:


文件类型并不重要,但您可能还需要将签入/签出流程与SharePoint合并。您需要收集此过程的其他详细信息,最好与SharePoint管理员联系以获取更多信息。

我们可以使用脚本任务上载。 首先,我们需要在运行SSIS包的系统中安装(共享点客户端)

请参阅以下VS2015上的脚本任务C#代码

#region Namespaces
using System.Windows.Forms;
using Microsoft.SharePoint.Client;
using System.Security;
using System.Net;
using Microsoft.SharePoint;
using System.IO;
using Microsoft.SqlServer.Dts.Runtime;
using System;
using System.Data;
#endregion

namespace ST_14e7d12d30c54d54a1eaa0bfa5961c5b
{

    [Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
    public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
    {



        public static class Utils
        {

            public static SharePointOnlineCredentials GetO365Credentials(string userName, string passWord)
            {
                SecureString securePassWord = new SecureString();

                foreach (char c in passWord.ToCharArray()) securePassWord.AppendChar(c);

                SharePointOnlineCredentials credentials = new SharePointOnlineCredentials(userName, securePassWord);

                return credentials;

            }
        }

        public void Main()
        {

            try
            {

                //Set the Sharepoint URL (Till the folder that the files needs to be uploaded)
                string siteUrl = "https://AAAAAAAAA.sharepoint.com/BBBBBBBB/CCCCCCCC";


               //FQDN source file details passing from the package 
                string filePath = @Dts.Variables["User::SharePoint_SrcFile"].Value.ToString();

                //Destination File Path (inclueds file name and full share point adddress)
                string DestinationfilePath = @Dts.Variables["User::Sharepoint_DestLocation"].Value.ToString();

                //loging the processing file
                bool fireAgain = true;
                Dts.Events.FireInformation(0,"","Source File Processing:" + filePath + " || Share Point Dest:" + DestinationfilePath,"", 0,ref fireAgain);

                //Setting the library name (can find from the share point site)
                string libraryName = "Documents";

                ClientContext ctx = new ClientContext(siteUrl);

                ctx.RequestTimeout = 1000000;

                //Retriveng user name and password from project parameeter (Password set as sensitive)
                string sharepointusername = @Dts.Variables["$Project::sSharePointUserName"].Value.ToString();
                string sharepointPassword = @Dts.Variables["$Project::sSharePointPassword"].GetSensitiveValue().ToString();


                //Authenticating (using the sharepoint client installed)
                ctx.Credentials = Utils.GetO365Credentials(sharepointusername, sharepointPassword);

                Web web = ctx.Web;
                ctx.Load(web, a => a.ServerRelativeUrl);

                List docs = web.Lists.GetByTitle(libraryName);

                ctx.ExecuteQuery();


                using (FileStream fs = new FileStream(filePath, FileMode.Open))

                {

                    FileCreationInformation flciNewFile = new FileCreationInformation();

                    flciNewFile.ContentStream = fs;

                    flciNewFile.Url = Path.GetFileName(filePath);

                    flciNewFile.Overwrite = true;

                    //Upload URL

                    flciNewFile.Url = DestinationfilePath.ToString() ;


                    Microsoft.SharePoint.Client.File uploadFile = docs.RootFolder.Files.Add(flciNewFile);

                    //ctx.Load(uploadFile);
                    uploadFile.ListItemAllFields["Title"] = "sharepoint";
                    uploadFile.ListItemAllFields.Update();

                    ctx.ExecuteQuery();

            }




        }
            catch (Exception ex)
            {
                Dts.Events.FireError(0,"", ex.Message, "", 0);
            }


        }

        #region ScriptResults declaration

        enum ScriptResults
        {
            Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
            Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
        };
        #endregion
“请共享代码”?你试过什么?这不是一个代码编写服务。