javascriptc#-4.0web-scraping

Save file directly to specified path without showing save or open dialogue


I'm invoking javascript in a web page using

webBrowser2.Document.InvokeScript("download_file");`. 

This javascript opens dialogue asking user to save or open the file. I want to save the file directly to the path without showing the dialogue to user. How can i achieve this. I'm scraping the web page. I'm extracting the required details from the web page.

download_file():

function download_file() {
    var summaryFlag = 0;
    if (document.getElementById("frmincludefilesummary").checked) {
        summaryFlag = 1;
    }
    url = '/filedatabase/file_process_request.html?mru=53616c7&type=doc';
    url += '&sum=' + summaryFlag + '&logo=0&xcode=name&serve_txt=0&folderid=';
    document.location = url;
}​

Solution

  • The thing you are trying to achieve is not possible. Javascript cannot access or write to the client filesystem directly. If allowed it would be a huge security breach.

    Alternate options would be to make use of flash or java or activeX.