1
 2protected void  Button1_Click(object sender, EventArgs e)
 3{
 4
 5    //*************文件的下载的实现**************
 6
 7
 8     string path = Server.MapPath("~/image/此情可待.wma");
 9           
10 //string path1 = Server.MapPath("~/image/PabloCastro.jpg");
11
12             
13//string path = Server.MapPath("~/image/PabloCastro.jpg");
14            System.IO.FileInfo file = new System.IO.FileInfo(path);
15            string filename = file.Name.ToString();
16            
17// clear the current output content from the buffer
18            
19Response.Clear();
20            
21// add the header that specifies the default filename for the Download/SaveAs dialog
22           
23 Response.AppendHeader("Content-Disposition""attachment; filename=\"" + Server.UrlEncode(filename) + "\"");//ture解决名字乱码现象
24
25           
26 //Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);//乱码
27            
28// add the header that specifies the file size, so that the browser
29            
30// can show the download progress
31            
32Response.AddHeader("Content-Length", file.Length.ToString());
33            
34// specify that the response is a stream that cannot be read by the
35            
36// client and must be downloaded
37            Response.ContentType = "application/octet-stream";
38 
39            
40// send the file stream to the client
41            
42            
43Response.WriteFile(file.FullName);
44            
45// stop the execution of this page
46            
47Response.End();
48
49 
50            
51
52}