2.0下载:


   

        string fileName = "tempimg.jpg";  //下载到客户端后的文件


        string filePath = Server.MapPath("../imgs/img7.jpg"); //要下载的服务器的文件路径


        FileInfo fileInfo = new FileInfo(filePath);  


        Response.Clear();

        Response.ClearContent();

        Response.ClearHeaders();


        Response.Buffer = true;   //设置文档缓存


        Response.AddHeader("Content-Disposition","p_w_upload;filename="+fileName);

        Response.AddHeader("Content-Length",fileInfo.Length.ToString());

        Response.AddHeader("Content-Transfer-Encoding","binary");


        Response.ContentType = "application/octet-stream";

        Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");


        Response.WriteFile(fileInfo.FullName);

        Response.Flush();

        Response.End();



3.5下载:



        

        string fileName = "tempimg.jpg";  //下载到客户端后的文件


        string filePath = Server.MapPath("../imgs/img7.jpg"); //要下载的服务器的文件路径


        Response.Clear();

        Response.Buffer = true;   //设置文档缓存

        Response.AddHeader("Content-Disposition", "p_w_upload;filename=" + fileName);


        Response.ContentType = "application/unknown";

        Response.TransmitFile(filePath);

        Response.End();