Download File with IE

Welcome Forums General PowerShell Q&A Download File with IE

This topic contains 1 reply, has 2 voices, and was last updated by

 
Keymaster
2 years, 6 months ago.

  • Author
    Posts
  • #46558

    Participant
    Points: 0
    Rank: Member

    Hi,

    I am trying to download a file from a website I am able to download it

    ($iexplorer.Document.getElementById('ctl00_ph1_rv_up_tcPM_CtrlTabHeader_fvReq_ctlFileID_ctlFileID_cmdName')).click()

    now comes a save as popup at bottom of IE and this is how I am handling it as of now, using WASP.dll

    Select-Window iexplore |Set-WindowActive |Select-ChildWindow -Passthru |Send-Keys "%{s}"

    this saves the file.
    I want to make my code wait till the file completely gets downloaded and get the filename that it shows in saveas box.
    Suggestions please.

    Thanks

  • #46742

    Keymaster
    Points: 1,785
    Helping HandTeam Member
    Rank: Community Hero

    You probably can't. The old IE COM object doesn't provide that kind of callback to let your code know the download is done. And there's nothing native in PowerShell to do this; what people will usually do is instantiate a WebRequest object in .NET and request the specific file from the web server. The .NET class provides asynchronous callbacks, meaning you provide a chunk of code to run once the download is done. There are some third-party modules that work similarly. But that IE COM object is over a decade old, isn't updated anymore (it's officially deprecated, and it'll probably start to go away with the shift to Edge), and just doesn't provide a lot of advanced functions.

The topic ‘Download File with IE’ is closed to new replies.