Link to home
Start Free TrialLog in
Avatar of AlHal2
AlHal2Flag for United Kingdom of Great Britain and Northern Ireland

asked on

pressing download button in c#

Please see http://www.bmfbovespa.com.br/en_us/products/indices/broad-indices/brazil-broad-based-index-ibra-composition-index-portfolio.htm
At the bottom of the page there is a download button.
How do I press this download button from a C# program?
Avatar of zephyr_hex (Megan)
zephyr_hex (Megan)
Flag of United States of America image

You can't "press  a button" from server side code.  C# runs before the page is loaded to the client.  Interactions, like button pressing, occur on the client side.  If you want to press a button, you must use a client side language, like jQuery / JavaScript.
Avatar of AlHal2

ASKER

I've used a tiny bit of JavaScript in my own webpages.  This page is not my own.
How would I go about it.  Do you have any sample code?
This will click the link:

$("a[id$='Conteudo_Export_Test']").click();

Open in new window


You will want to wrap that inside a document ready function, so that it doesn't run until the DOM is loaded.

Here is a demo:  https://jsfiddle.net/zephyr_hex/rg90u61v/

HTML

<a href="" id="ctl00_contentPlaceHolderConteudo_Export_Test">Download</a>
<span></span>

Open in new window


jQuery

$(document).ready(function() {
   //test:  capture the click event
	$("a[id$='Conteudo_Export_Test']").on('click', function() {
  $('span').append('The link was clicked');
  });

  //click the Download link
	$("a[id$='Conteudo_Export_Test']").click();
});

Open in new window

Avatar of AlHal2

ASKER

Thanks.  How can I schedule this to run at a particular time of day?
Avatar of AlHal2

ASKER

I've put this into a sample webpage.  How do I determine where the downloaded file goes?

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
   
   
        $(document).ready(function () {
            //test:  capture the click event
            $("a[id$='Conteudo_Export_Test']").on('click', function () {
                $('span').append('The link was clicked');
            });

            //click the Download link
            $("a[id$='Conteudo_Export_Test']").click();
        });
    
    
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    
    

        
        <a href="" id="ctl00_contentPlaceHolderConteudo_Export_Test">Download</a>
    
</asp:Content>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of zephyr_hex (Megan)
zephyr_hex (Megan)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AlHal2

ASKER

Thanks.