62,041
社区成员
发帖
与我相关
我的任务
分享
//从web.config读取文件上传路径
string strFileUploadPath = ConfigurationManager.AppSettings["FileUplodePath"].ToLower();
//从列表框中读取选择的文件
string strFileName = lb_FileList.SelectedValue;
//组合成物理路径
//string FullFileName = Server.MapPath(strFileUploadPath + "/") + strFileName;
string FullFileName = Server.MapPath(strFileUploadPath + "//" + strFileName);
FullFileName = Server.UrlDecode(FullFileName);//后加的
FileInfo DownloadFile = new FileInfo(FullFileName);
Response.Clear();
Response.ClearHeaders();
Response.Buffer = false;
Response.ContentType = "application/octet-stream ";
Response.AppendHeader("Content-Disposition ", "attachment;filename= "
+ HttpUtility.UrlEncode(DownloadFile.FullName, System.Text.Encoding.UTF8));
Response.AppendHeader("Content-Length ", DownloadFile.Length.ToString());
Response.WriteFile(DownloadFile.FullName);
Response.Flush();
Response.End();