Hi Guys,
I want to download a .zip file from https site. The manual process is double click on the link and message pop up save the file hit SAVE and done.
I am in the process of automating this process Once a week through SSIS. Here is my SSIS Package looks like.
-
Create Two Variables ( VarURL, VarDestinationFileSaved)
-
Script Task
Here is the code that I am using C# Code.
public void Main()
{
// TODO: Add your code hereVariables varCollection = null; Dts.VariableDispenser.LockForRead("User::VarURL"); Dts.VariableDispenser.LockForRead("User::VarDestinationFileSaved"); Dts.VariableDispenser.GetVariables(ref varCollection); System.Net.WebClient myWebClient = new System.Net.WebClient(); string webResource = varCollection["User::VarURL"].Value.ToString(); string fileName = varCollection["User::VarDestinationFileSaved"].Value.ToString() + webResource.Substring(webResource.LastIndexOf('/') + 1); myWebClient.DownloadFile(webResource, fileName); Dts.TaskResult = (int)ScriptResults.Success; }
However, I am getting Error.
" at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()"
I am not good in C#. Anyone, please advise me (it is urgent please). Thank You in advance.