Downloading Files through the Web Browser Control

I have embedded the webBrowser control in my C# program. And I am navigating it to a page that I created where I try to invoke a download by setting my headers to this:

header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=$transport_var3.xls");
print("$xlsheader\n$xlsdata");

Has anyone been successful in using Content-Disposition in IE 6.0
If so please let me know how.

Any ideas


Answer this question

Downloading Files through the Web Browser Control

  • Steve Starck

    Found the answer:

     I'd been trying to figure out why I couldn't get Internet Explorer to download a file if I used session_start().  It only happened with certain files.  Here's the undocumented (I couldn't find anything on it) skinny that I've come up with:

    If the content type (sent in the Content-type header) is not known to Windows AND the cache-control header contains 'no-store' or 'no-cache' I.E. will error out.  I'm using WindowsXP Home and I.E. 6.0.

    Both 'no-store' and 'no-cache' cause the error by themselves and individually.  I've found that always replacing the header with one that excludes those lines works:

    <
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    >

    This error would happen when using any PHP function (or anything else for that matter) that may set 'no-store' and/or 'no-cache' in the Cache-control header.  Provided the content type is not known to Windows.

    E.g.

    <

    // this works
    header("Content-type: text/plain");
    header("Cache-Control: no-store, no-cache");
    echo($data);

    // this does not work
    header("Content-type: foo/bar");
    header("Cache-Control: no-store, no-cache");
    echo($data);

    >


  • Downloading Files through the Web Browser Control