jaiswalm
jaiswalm

Reputation: 131

How to download XML file from URL using C# or VB.Net Script Task in SSIS

I am trying to download an XMLFile output from the SSRS Report. I am having issues in Script Task of C# and VB.Net

I am getting below issue

Exception has been thrown by the target of an invocation.

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()

Dim myURL As String
myURL = "https://exmaple.com/XMLFileForDownLoad"

Dim WinHttpReq As Object


WinHttpReq = CreateObject("Microsoft.XMLHTTP")
WinHttpReq.Open("GET", myURL, False)
WinHttpReq.Send

myURL = WinHttpReq.ResponseBody
Dim oStream As Object = Nothing
If WinHttpReq.Status = 200 Then
    oStream = CreateObject("ADODB.Stream")
    oStream.Open
    oStream.Type = 1

    oStream.Write(WinHttpReq.ResponseBody)
    oStream.SaveToFile("C:\temp\file.xml")
    oStream.Close
End If

I want to download file in the Local

Upvotes: 1

Views: 646

Answers (1)

jaiswalm
jaiswalm

Reputation: 131

I was able to solve using VBScript following below and it worked as desired.

Execute and Download SSRS Report as XML using SSIS

Upvotes: 1

Related Questions