0

このコードを使用してファイルをダウンロードしていますが、エラーがスローされます。取り扱いを手伝ってください。

スレッドが中止されました。

protected void Download_Click(object sender, EventArgs e)
{
    try
    {
        string filePath = Convert.ToString(Attachment);
        string fullFilePath = ("../../SiteImages/" + "donald.jpg");
        Response.Clear();
        Response.ClearHeaders();
        Response.ClearContent();
        Response.AddHeader("Content-Disposition", "attachment; filename=\"" + Path.GetFileName(fullFilePath) + "\"");
        Response.ContentType = ContentType;
        Response.TransmitFile(fullFilePath);
        //MngLogs.InsertAuditsInfo("Tender downloaded via" + " " + MngLogs.PageName, MngLogs.UserMacAddress, MngLogs.UserIPAddress, UserID, "Download");
        //Response.End();
    }
    catch (Exception ex)
    {
        Utility.Msg_Error(Master, ex.Message);
    }
}
4

2 に答える 2

0

このダウンロード アプローチは機能しますか?

try
{
    using (var client = new WebClient())
    {
        client.DownloadFile(urlToFileOnInternet, pathToFileOnComputer);
    }
}
catch (Exception ex)
{
    Utility.Msg_Error(Master, ex.Message);
}

お役に立てれば。

于 2016-07-28T09:30:50.153 に答える
0

交換

Response.End();

これとともに:

HttpContext.Current.Response.Flush();
HttpContext.Current.Response.SuppressContent = true;
HttpContext.Current.ApplicationInstance.CompleteRequest();

Response.End();常に例外をスローすると、現在のスレッドが中止されます。この動作の詳細については、こちらを参照してください: Response.End() は有害と見なされますか? Response.End()「スレッドが中止されました」の回避方法 Excel ファイルのダウンロード中の例外

于 2016-07-28T09:33:56.647 に答える