【问题标题】:C# 2010 - Download File From Sharepoint ErrorC# 2010 - 从 Sharepoint 下载文件错误
【发布时间】:2015-09-30 18:29:40
【问题描述】:

我想知道您是否可以帮助我,我是初学者,我正在尝试在 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.Net;
using System.Configuration.Assemblies;
using System.IO;

namespace ST_3b90f3dd23cf4b25bb1e0175ac566fde.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()
    {
        System.Net.WebClient client = new System.Net.WebClient();

        client.UseDefaultCredentials = true;

        string urlOfTheSPFile = "https://sharepointlocation";
        string localPathToTheFile = @"C:\localfolder";
        client.DownloadFile(urlOfTheSPFile, localPathToTheFile);
        client.Dispose();

        Dts.TaskResult = (int)ScriptResults.Success;
    }
}
}

这似乎在 Visual Studio 2008 上运行良好,但现在我使用的是 VS 2010 (C# 2010),我无法让它运行。

希望你能帮助我。

谢谢!

【问题讨论】:

  • 您是否遇到任何错误?

标签: c# visual-studio visual-studio-2010 sharepoint ssis


【解决方案1】:

尝试在远程路径之前使用@,并尝试使用客户端而不是必须处理。

  var remotefile = @"https://pathtoremotefile";
    var localfile = @"C:\pathtolocalfile";
    using(WebClient wc = new WebClient())
    {
        wc.Credentials = CredentialCache.DefaultNetworkCredentials;
        // or new System.Net.NetworkCredential("user","pass","domain");
        wc.DownloadFile(remotefile,localfile);
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-11
    • 2015-09-17
    • 1970-01-01
    • 2011-12-04
    • 2020-09-22
    • 2012-11-16
    • 1970-01-01
    相关资源
    最近更新 更多