0

I am automating Internet Explorer using SHDocVW.dll and MSHTML with C#, and I wish to save an image from the page to the disk (JPEG format).

I can't use the WebClient class to download the image; if I do it, I end up downloading the site's login page. I can't print the screen either, because the browser has to remain invisible during this process, running in the background.

I have tried to do the following:

IHTMLImgElement imgElement = ...;
IHTMLControlRange imgRange = ...;

imgRange.add(imgElement as IHTMLControlElement);
imgRange.execCommand( "copy", false, null );

This does nothing. I am not able to extract anything from the clipboard. Every solution I found didn't work for me.

orde
  • 5,233
  • 6
  • 31
  • 33
  • I changed my approach. I am now monitoring Internet Explorer's temp files folder, so I know when a new image file is created. Then I simply copy it wherever I want. – Cphrreiuslo Oct 29 '15 at 19:41

1 Answers1

0

Your webclient approach is probably missing cookies... see How do I log into a site with WebClient? for an example that handles cookies.

your code looks fine except the user has to change the security setting to enable clipboard access. If the image is cached on disk you can dig the WinInet cache after parsing the page for the image location.

Sheng Jiang 蒋晟
  • 15,125
  • 2
  • 28
  • 46