现在的位置: 首页 > 综合 > 正文

C#下载代码,防迅雷

2012年07月27日 ⁄ 综合 ⁄ 共 554字 ⁄ 字号 评论关闭

protected void btn_Download_Click(object sender, EventArgs e)
    {
        string strFileUploadPath = "Files/";
        //从列表框控件中读取选择的文件名
        string strFileName = lb_FileList.SelectedValue; //组合成物理路径
        string strFilePhysicalPath = Server.MapPath("~/" + strFileUploadPath + strFileName);
        Response.Clear();
        Response.ContentType = "application/octet-stream";
        Response.AddHeader("Content-Disposition", "attachment;FileName=" + HttpUtility.UrlEncode(strFileName, System.Text.Encoding.UTF8));
        Response.WriteFile(strFilePhysicalPath);
        Response.End();
    }

 

抱歉!评论已关闭.