C# mshtml.HTMLWindow2 execScript doesnt copy image


  • mshtml.HTMLWindow2 execScript doesnt copy image.


    w2.execScript("var ctrlRange = document.body.createControlRange();ctrlRange.add(document.getElementById('form').getElementsByTagName('IMG')[0]);ctrlRange.execCommand('Copy');", "javascript");

    System.Drawing.Image retImage = Clipboard.GetImage();

    retImage is null. 

    in html there is image

    Thursday, March 08, 2018 3:13 PM

All replies

  • The WebBrowser control is for desktop applications. All browsers are the client portion of client/server applications.

    You don't specify how you tested it locally but you could not have gotten it to work if you tested it in a server such as the server provided by Visual Studio or a local instance of IIS.

    Sam Hobbs

    Thursday, March 08, 2018 6:58 PM
  • When i publish it any normal windows platforms it works. When i publish it win server 2012 r2 doesnt work

    Software Engineer

    Thursday, March 08, 2018 7:06 PM
  • I don't know how it is possible but this looks totally different from the question I replied to. The question I replied to was the same as many other questions; the same question was posted at least four times.

    Sam Hobbs

    Thursday, March 08, 2018 10:16 PM
  • Based on what this question said earlier, you are trying to use a WebBrowser in the server. It should not work in a server.

    Sam Hobbs

    Thursday, March 08, 2018 10:18 PM
  • Hello Soner,

    Your question is more related to office, you could repost a new thread to ASP.NET forum for professional support.

    The Visual C# discuss and ask the C# programming language, IDE, libraries, samples and tools. If you have some grammar or code errors, please feel free to contact us.

    Best Regards,

    Neil Hu

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Friday, March 09, 2018 8:39 AM