c# 파일 다운로드 - 파일 스트림으로

1087 단어
///   
    ///       
    ///   
    ///      
    ///     
    public void BigFileDownload(string FileName, string FilePath)
    {
        try
        {

            //           
            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;charset=gb2321";

            //              ;         
            Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8));
            Response.BinaryWrite(bytes);
            Response.Flush();
            Response.End(); 
        }
        catch (Exception ex)
        {
            
        }
        finally
        {
            Response.Flush();
            Response.End(); 
        }
    }  

 
전재 대상:https://www.cnblogs.com/ly77461/p/6807251.html

좋은 웹페이지 즐겨찾기