Add this in your page_loadCode:
Page. response. Clear ();
Bool Success = Responsefile (page. Request, page. response, "Target FileName " , @" Source FilePath " , 1024000 );
If ( ! Success)
Response. Write ( " An error occurred while downloading the file! " );
Page. response. End ();
Function Code for file download: Public Static Bool Responsefile (httprequest _ Request, httpresponse _ response, String _ Filename, String _ Fullpath, Long _ Speed)
{
Try
{
Filestream myfile = New Filestream (_ fullpath, filemode. Open, fileaccess. Read, fileshare. readwrite );
Binaryreader br = New Binaryreader (myfile );
Try
{
_ Response. addheader ( " Accept-ranges " , " Bytes " );
_ Response. Buffer = False ;
Long Filelength = Myfile. length;
Long Startbytes = 0 ;
Double Pack = 10240 ; // 10 K bytes
// Integer sleep = 200; // 5 times per second, that is, 5*10 K bytes per second
Int Sleep = ( Int ) Math. Floor ( 1000 * Pack / _ Speed) + 1 ;
If (_ Request. headers [ " Range " ] ! = Null )
{
_ Response. statuscode = 206 ;
String [] Range = _ Request. headers [ " Range " ]. Split ( New Char [] {'=','-'} );
Startbytes = Convert. toint64 (range [ 1 ]);
}
_ Response. addheader ( " Content-Length " , (Filelength - Startbytes). tostring ());
If (Startbytes ! = 0 )
{
//Response. addheader ("content-range", String. Format ("bytes {0}-{1}/{2}", startbytes, fileLength-1, filelength ));
}
_ Response. addheader ( " Connection " , " Keep-alive " );
_ Response. contenttype = " Application/octet-stream " ;
_ Response. addheader ( " Content-Disposition " , " Attachment; filename = " + Httputility. urlencode (_ filename, system. Text. encoding. utf8 ));
BR. basestream. Seek (startbytes, seekorigin. Begin );
Int Maxcount = ( Int ) Math. Floor (filelength - Startbytes) / Pack) + 1 ;
For ( Int I = 0 ; I < Maxcount; I ++ )
{
If (_ Response. isclientconnected)
{
_ Response. binarywrite (Br. readbytes (Int. Parse (pack. tostring ())));
Thread. Sleep (sleep );
}
Else
{
I=Maxcount;
}
}
}
Catch
{
Return False;
}
Finally
{
BR. Close ();
Myfile. Close ();
}
}
Catch
{
Return False;
}
Return True ;
}
in this way, when downloading an object, the open/save window is displayed no matter what format the object is.