我想知道你是否可以帮助我,我是初学者,我正在尝试在SSIS项目中使用“脚本任务”,该项目应该从sharepoint下载文件并将其保存在本地文件夹中:
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),我无法让它运行。
希望你能帮助我。
谢谢!
答案 0 :(得分:0)
尝试在remotepath之前使用@并尝试使用客户端而不必处置。
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);
}