Tag: response.transmitfile

使用Response.TransmitFile使物理文件无法正常工作

我正在尝试使用Response.TransmitFile()来提示下载。 我已经阅读了关于这个问题的一些post,并根据Rick Strahl的博客http://www.west-wind.com/weblog/posts/76293.aspx找到了我的方法。 唯一的区别(我可以告诉)是我的目标是虚拟目录之外的物理文件。 这个代码是在ajaxified radgrid中调用的……我想知道response.transmitfile是否不适用于ajax调用? 这是我的代码片段: // Get the physical Path of the file string docFilePath = (string)args.AttachmentKeyValues[“DocFilePath”]; // Create New instance of FileInfo class to get the properties of the file being downloaded FileInfo file = new FileInfo(docFilePath); // Checking if file exists if (file.Exists) { Response.ClearContent(); Response.AddHeader(“Content-Disposition”, “attachment; filename=” + file.Name); Response.AddHeader(“Content-Length”, […]

Response.TransmitFile并在传输后删除它

我必须在我的网站上实施GEDCOM导出。 点击导出到gedcom后,我的.net代码在服务器上创建了一个文件。 然后我需要从服务器下载它到客户端,并且应该询问用户保存该文件的位置,这意味着需要savedialog。 下载后,我想从服务器上删除该文件。 我有一个代码将文件从服务器传输到客户端: Response.ContentType = “text/xml”; Response.AppendHeader(“Content-Disposition”, “attachment; filename=” + FileName); Response.TransmitFile(Server.MapPath(“~/” + FileName)); Response.End(); 从这个链接 但是我无法在此代码之后删除该文件,因为Response.End结束响应,因此在该行之后写入的任何代码都不会执行。 如果我在Response.End();之前执行代码删除文件Response.End(); ,然后文件没有传输,我收到一个错误。