知识学堂 > 课程 > asp.net文件下载

asp.net文件下载

发布日期:2018/12/24 来源:聚恒【返回】

        string filePath = Server.MapPath("/Management/Upload/" + DownLoad.guid + "/" + DownLoad.filename1);
        FileStream fs = new FileStream(filePath, FileMode.Open);
        byte[] bytes = new byte[(int)fs.Length];
        fs.Read(bytes, 0, bytes.Length);
        fs.Close();
        Response.ContentType = "application/octet-stream";
        Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(DownLoad.filename1, System.Text.Encoding.UTF8));
        Response.BinaryWrite(bytes);
        Response.Flush();
        Response.End();