確定我正在從服務器下載文件,我打算把它刪除大幹快上的客戶端下載後,我已在服務器上下載的文件..從服務器上下載一個文件,然後刪除服務器
我的下載代碼工作正常,但我不知道什麼時候該命令刪除該文件。
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