在ASP Webform C#中下载文件后打印文本

时间:2018-08-31 09:08:27

标签: c# asp.net

我想在网页上打印训练方法的状态。并下载日志文件。这是我的代码:

 string fileout = "AddLabelLog_" + dates + ".log";
    string fileoutput = Server.MapPath("~/TrainLog/") + fileout;

    System.Web.HttpResponse response1 = System.Web.HttpContext.Current.Response;
    response1.ClearContent();
    response1.Clear();
    response1.ContentType = "text/html";
    response1.AddHeader("Content-Disposition",
                       "attachment; filename=" + fileout);
    response1.TransmitFile(fileoutput);
    response1.Flush();
    response1.End();

    var strLines = File.ReadLines(fileoutput);
    foreach (var line in strLines)
    {
        if (line.Contains("FAILED"))
        {
            Result1.Text = "Your Training Is Failed. Please Check The Log.";
            break;


        }
        else
        {
            Result1.Text = "Your System Has been Trained";

        }
    }

我发现问题在于此代码:

System.Web.HttpResponse response1 = System.Web.HttpContext.Current.Response;
response1.ClearContent();
response1.Clear();
response1.ContentType = "text/html";
response1.AddHeader("Content-Disposition",
                   "attachment; filename=" + fileout);
response1.TransmitFile(fileoutput);
response1.Flush();
response1.End();

如果放置用于下载文件的代码,它将无法打印Result1.Text。我该怎么做才能在Result1.Text中打印消息并下载文件?

0 个答案:

没有答案