小编Pot*_*man的帖子

C#Response.WriteFile与Response.TransmitFile文件大小问题

我在服务器上有一个5Mb的pdf,使用writeFile下载这个文件给我一个15Mb的下载,其中transmitfile给出正确的5Mb文件大小...

这是由于writeFile服务器上的某种内存未压缩?只是想知道是否有人看到同样的事情发生...

(ps因为我们去了iis7才发现它?)

代码是......

if (File.Exists(filepath))
{
    HttpContext.Current.Response.Clear();
    HttpContext.Current.Response.ContentType = "application/octet-stream";
    HttpContext.Current.Response.AddHeader("content-disposition","attachment;filename=\""+Path.GetFileName(filepath)+"\"");
    HttpContext.Current.Response.AddHeader("content-length", new FileInfo(filepath).Length.ToString());

    //HttpContext.Current.Response.WriteFile(filepath);
    HttpContext.Current.Response.TransmitFile(filepath);

    HttpContext.Current.Response.Flush();
    HttpContext.Current.Response.Close();
}
Run Code Online (Sandbox Code Playgroud)

c# transmitfile

8
推荐指数
1
解决办法
2万
查看次数

标签 统计

c# ×1

transmitfile ×1