How to read URL which has PDF format in SSIS

  • I Have a URL when we browse on the UI it open the PDF file.

    Here is the sample URL- https://abciruat.net:1223/ASDFLink/VisualServerget&pVersion=0046&VisualRep=D1&docId=737474784&VisId=data&accesMode=r&authId=SD%12%33%4565%556%84WebAS%20O%%20C%3DDE&expiration=20210908165305&secKey=MIIBUgZI

     

    When we browse the above sample URL it opens content in PDF format.

    My requirement is how can i use this URL in SSIS using script task and download the PDF from this URL and save in local path?

     

    I tried below scenario but didnt worked.

    I created variable called FileName - C:\Test\

    Added HTTP Connection Manager and in the server URL i provided the URL link

    Added Script task in Control Flow and used this FileName variable in ReadOnlyVariables

    Inside the script i used the below logic.

    public void Main()

    {

    string FilePath = Dts.Variables["User::FilePath"].Value.ToString();

    object obj = Dts.Connections["HTTP Connection Manager"].AcquireConnection(null);

    HttpClientConnection HTTPConnection = new HttpClientConnection(obj);

    HTTPConnection.DownloadFile(FilePath, true);

    // TODO: Add your code here

    Dts.TaskResult = (int)ScriptResults.Success;

    }

     

    When i run the package its giving me error -

    An exception of type 'System.IO.DirectoryNotFoundException' occurred in Microsoft.SqlServer.ManagedDTS.dll but was not handled in user code

    Additional information: The system cannot find the path specified. (Exception from HRESULT: 0x80070003)

  • The error message is telling you EXACTLY what is wrong - the path was not found.

    Looking at your code, there are a few things that I am a little confused on, the first being - what part of your code is actually handling the URI?  On top of that, you say you created a variable named "FileName" but you are not using it in your scripting section.  My GUESS is that FilePath is a typo or possibly the URI?

    Either way, I think your code is wrong which is what the problem is.  If I remember right (it has been a while), DownloadFile takes 2 arguments, neither of which are booleans - they are both strings.  The first is the URI for the web site, the second is the location to save the file.  My guess here is that the "cannot find path specified" is because you are trying to save to "true" which makes no sense.

    Now, a quick google of your problem led me to this site:

    https://stackoverflow.com/questions/6684317/how-to-make-an-http-request-from-ssis

    which has instructions on how to make an HTTP request from SSIS scripting task to download a file.  You would need to modify it to suit your needs, but I'd probably follow their example, but you could try modifying your code to make it work.  I personally like the one on stack overflow a bit nicer than yours.  Longer, but a bit safer to ensure the variables in SSIS are not changing while you are reading them...

    The above is all just my opinion on what you should do. 
    As with all advice you find on a random internet forum - you shouldn't blindly follow it.  Always test on a test server to see if there is negative side effects before making changes to live!
    I recommend you NEVER run "random code" you found online on any system you care about UNLESS you understand and can verify the code OR you don't care if the code trashes your system.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply