确定我正在从服务器下载文件,我打算把它删除大干快上的客户端下载后,我已在服务器上下载的文件..从服务器上下载一个文件,然后删除服务器
我的下载代码工作正常,但我不知道什么时候该命令删除该文件。
string filepath = restoredFilename.ToString();
// Create New instance of FileInfo class to get the properties of the file being downloaded
FileInfo myfile = new FileInfo(filepath);
// Checking if file exists
if (myfile.Exists)
{
// Clear the content of the response
Response.ClearContent();
// Add the file name and attachment, which will force the open/cancel/save dialog box to show, to the header
Response.AddHeader("Content-Disposition", "attachment; filename=" + myfile.Name);
//Response.AddHeader("Content-Disposition", "inline; filename=" + myfile.Name);
// Add the file size into the response header
Response.AddHeader("Content-Length", myfile.Length.ToString());
// Set the ContentType
Response.ContentType = ReturnExtension(myfile.Extension.ToLower());
//// Write the file into the response (TransmitFile is for ASP.NET 2.0. In ASP.NET 1.1 you have to use WriteFile instead)
Response.TransmitFile(myfile.FullName);
// End the response
Response.End();
}
现在我知道到Response.End()将停止每一件事情,并返回值,所以是有另一种方式也这样做..
我需要调用一个函数
DeleteRestoredFileForGUI(restoredFilename);
删除的文件,但不知道放在哪里。我试图把之前和之后到Response.End(),但它不工作..
任何帮助表示赞赏...谢谢
它会运行此页面代码。而不是做response.end()运行response.redirect(“〜/ page-for-delete.aspx?file = delete.dat”,false); - 通过添加false,您继续处理此页面上的信息。 – Kieran 2010-02-02 00:05:50
@Kieran,TransmitFile将限制文件传输时的响应,并且Response.Redirect将导致响应冲突。 – 2010-02-02 00:24:17