C#文件下载

来源:互联网 发布:flappy bird ios源码 编辑:程序博客网 时间:2024/05/05 02:40

 private void FileDownload_One(string FullFileName)
    {
        try
        {
            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();
           
        }

        catch (System.Exception ex)
        {
            Response.Write(ex.Message);
        }
    }