SSIS通过ccl脚本中的webclient下载http文件。非法字符错误,因为源URL有cgi?在路上

时间:2014-10-03 14:51:35

标签: c# ssis webclient

我运行了一个SSIS脚本,该脚本使用C#脚本运行webclient从XE.com下载货币文件。不幸的是,路径XE提供了一个cgi调用,因此在其中有一个问号,这是一个非法字符,所以当我运行脚本时收到以下内容:

System.ArgumentException:路径中的非法字符。

我使用的脚本只是改编自这些说明: How to make an HTTP request from SSIS?

有没有办法用ASCII代码替换问号?

非常感谢提前。

1 个答案:

答案 0 :(得分:0)

感谢您的回复,Ben。在分钟内,这是一个SSIS脚本任务,其中包含上述指南中的代码。我最后用ASCII代码?替换了问号。 对于未来的读者,有问题的代码:

public void Main()
{
    Variables varCollection = null;

    Dts.VariableDispenser.LockForRead("User::RemoteUri");
    Dts.VariableDispenser.LockForRead("User::LocalFolder");
    Dts.VariableDispenser.GetVariables(ref varCollection);

    System.Net.WebClient myWebClient = new System.Net.WebClient();
    string webResource = varCollection["User::RemoteUri"].Value.ToString();
    string fileName = varCollection["User::LocalFolder"].Value.ToString() + webResource.Substring(webResource.LastIndexOf('/') + 1);
    myWebClient.DownloadFile(webResource, fileName);

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