Using system;
Using system. Data;
Using system. configuration;
Using system. collections;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;
Using system. xml;
Using system. IO;
Public partial class download: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
If (! Page. ispostback)
{
Mydatabind ();
}
}
Private void mydatabind ()
{
// Xmldocument xdc = new xmldocument ();
// Xdc. Load ("databasexml. xml ");
Dataset DS = new dataset ();
DS. readxml (server. mappath ("databasexml. xml "));
This. datalist1.datasource = Ds;
This. datalist1.databind ();
}
// Click Download
Protected void datalist1_editcommand (Object source, datalistcommandeventargs E)
{
// Response. Write ("ddddddddddddd ");
// Obtain the ID of the downloaded object
Int AA = convert. toint32 (E. commandargument. tostring ());
// The file name varies according to the ID.
String downloadfilename = "~ /Upfile/a.txt ";
String filepath = server. mappath (downloadfilename );
// Obtain the server name of the file
String filename = path. getfilename (filepath );
// Create a fileinfo class instance
Fileinfo file = new fileinfo (filepath );
Response. Clear ();
// File output type
Response. contenttype = "application/octet-stream ";
// Output file header
Response. addheader ("content-disposition", "attachment; filename =" + httputility. urlencode (filename, system. Text. encoding. utf8 ));
// Size of the input file
Response. addheader ("Content-Length", file. length. tostring ());
Response. Flush ();
// Output file
Response. writefile (filepath );
}
}