标签: transmitfile

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万
查看次数

Response.TransmitFile不下载,并且没有抛出错误

我目前正在使用HttpResponse从我的服务器下载文件.我已经有几个函数用于下载Excel/Word文件,但我无法下载简单的文本文件(.txt).

使用文本文件,我基本上将TextBox的内容转储到文件中,尝试使用HttpResponse下载文件,然后删除临时文本文件.

以下是适用于Excel/Word文档的代码示例:

protected void linkInstructions_Click(object sender, EventArgs e)
{
    String FileName = "BulkAdd_Instructions.doc";
    String FilePath = Server.MapPath("~/TempFiles/BulkAdd_Instructions.doc");
    System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
    response.ClearContent();
    response.Clear();
    response.ContentType = "application/x-unknown";
    response.AddHeader("Content-Disposition", "attachment; filename=" + FileName + ";");
    response.TransmitFile(FilePath);
    response.Flush();
    response.End();  
}
Run Code Online (Sandbox Code Playgroud)

这里有一大堆代码不起作用.
请注意,代码运行时不会出现任何错误.文件已创建并已删除,但从未转储给用户.

protected void saveLog(object sender, EventArgs e)
{ 
    string date = DateTime.Now.ToString("MM_dd_yyyy_hhmm");     //  Get Date/Time
    string fileName = "BulkLog_"+ date + ".txt";                //  Stitch File Name + Date/Time
    string logText = errorLog.Text;                             //  Get Text from TextBox
    string halfPath = "~/TempFiles/" …
Run Code Online (Sandbox Code Playgroud)

c# httpresponse text-files transmitfile response.transmitfile

7
推荐指数
3
解决办法
3万
查看次数

WriteFile vs TransmitFile用于传输后需要从服务器删除的大文件

我必须触发用户下载大文件到webbrowser,我在那里创建要在服务器上传输的文件,然后立即删除它.我已经找到足够的例子来看我应该使用Response.TransmitFile或Response.WriteFile ......但是听说两者都有问题:

WriteFile是同步的,但它会在将文件发送给用户之前将文件缓冲在内存中.由于我正在处理非常大的文件,这可能会导致问题.

TransmitFile不在本地缓冲,因此它适用于大文件,但它是异步的,所以我无法在调用TransmitFile后删除该文件.显然刷新文件并不保证我也可以删除它?

处理这个问题的最佳方法是什么?

还有BinaryWrite ......我可以遍历文件流,将其复制到段中吗?

c# asp.net writefile transmitfile

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