Writing MemoryStream to Response Object

后端 未结 8 1526
闹比i
闹比i 2020-11-27 20:03

I am using the following code to stream pptx which is in a MemoryStream object but when I open it I get Repair message in PowerPoint, what is the correct way of writing Memo

8条回答
  •  清歌不尽
    2020-11-27 20:49

    First We Need To Write into our Memory Stream and then with the help of Memory Stream method "WriteTo" we can write to the Response of the Page as shown in the below code.

       MemoryStream filecontent = null;
       filecontent =//CommonUtility.ExportToPdf(inputXMLtoXSLT);(This will be your MemeoryStream Content)
       Response.ContentType = "image/pdf";
       string headerValue = string.Format("attachment; filename={0}", formName.ToUpper() + ".pdf");
       Response.AppendHeader("Content-Disposition", headerValue);
    
       filecontent.WriteTo(Response.OutputStream);
    
       Response.End();
    

    FormName is the fileName given,This code will make the generated PDF file downloadable by invoking a PopUp.

提交回复
热议问题