Writing MemoryStream to Response Object

后端 未结 8 1457
闹比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:44

    I had the same problem and the only solution that worked was:

    Response.Clear();
    Response.ContentType = "Application/msword";
    Response.AddHeader("Content-Disposition", "attachment; filename=myfile.docx");
    Response.BinaryWrite(myMemoryStream.ToArray());
    // myMemoryStream.WriteTo(Response.OutputStream); //works too
    Response.Flush();
    Response.Close();
    Response.End();
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题