日期:2014-05-17  浏览次数:20494 次

在cs有一个http的rar包,如何弹出下载提示
在cs有一个http的rar包,如何弹出下载提示
------最佳解决方案--------------------
    private void DownLoadFile(string fName)
    {
        //文件路径
        string fPath = "~/Data/";
        string filePath = Server.MapPath(fPath + fName);
        //以字符流的形式下载文件
        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(fName, System.Text.Encoding.UTF8));
        Response.BinaryWrite(bytes);
        Response.Flush();
        Response.End();
    }

------其他解决方案--------------------
你直接给个文件路径就行了   超链接就行<a href="WebFile/文件.rar"> 文件名</a>,后台拼个字符串显示也许 
------其他解决方案--------------------
用这个方法,也有异常,下载下来文件不对。Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8));
                Response.WriteFile(filepath);


                Response.Flush();
------其他解决方案--------------------
直接访问那个rar包就行了
------其他解决方案--------------------
引用:
C# code?1234567891011121314151617    private void DownLoadFile(string fName)    {        //文件路径        string fPath = "~/Data/";        string filePath = Server.MapPath(fPath + fName);   ……

这个容易引起内存溢出
------其他解决方案--------------------
引用:
引用:C# code?1234567891011121314151617    private void DownLoadFile(string fName)    {        //文件路径        string fPath = "~/Data/";        string filePath = Server.Ma……

解决方法呢??
------其他解决方案--------------------
引用:
引用:引用:C# code?1234567891011121314151617    private void DownLoadFile(string fName)    {        //文件路径        string fPath = "~