0

Response.Flush メソッドが機能していません。pdfContent でデータを取得していますが、PDF ドキュメントを開いていません。以下はコードです。助けてください。

public ActionResult PdfClick(int requestid)
    {
        BusinessRequestController bsnrqstcntrlr = new BusinessRequestController();
        try
        {
             int DocId = (new BusinessRequestBR()).GetBaseLineDocumentsForSearch(requestid);
             byte[] PdfContent = (new BusinessRequestHelper()).GetBaseLineDonload(DocId);
             Response.Buffer = true;
             Response.Clear();
             Response.ContentType = "application/pdf";
             Response.AddHeader("content-disposition", "attachment; filename=" + "BaseLine_Doc" + "_" + DocId + ".pdf");
             Response.BinaryWrite(PdfContent);
             Response.Flush();
             return Content("");

        }
        catch (Exception ex)
        {
            throw this.log.CreatePropagatedException(ex);
        }
4

2 に答える 2

0

実行中のプロジェクトからコードを引き出す

Response.Clear();
Response.AddHeader("Content-Disposition","attachment; filename=\"" + file[0].Name + "\"");
Response.AddHeader("Content-Length", fileSize.ToString(_culture));                                         
Response.ContentType = Path.GetExtension(file[0].Name).GetMimeType();
Response.BufferOutput = false;
Response.AddHeader("Accept-Ranges", "bytes"); //tell the client that we accept byte-range requests

      while (totalBytesRead < fileSize)
         {
            if (!Response.IsClientConnected)
               {
                  System.Diagnostics.Debug.WriteLine("--> Client disconnected");
                         break;
                 }

                int bytesRead = fs.Read(buffer, 0, buffer.Length);
                Response.OutputStream.Write(buffer, 0, bytesRead);
                Response.Flush();
                totalBytesRead += bytesRead;
                                    }
   Response.End();

このコードは毎回機能します。必要に応じて操作してください。注: 変数はコードの上で定義されます。

于 2013-09-17T11:59:56.230 に答える