Click here to Skip to main content
15,884,778 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
 i replace text in presentationDocumentNew 
 Save file on Physical path - Its worked
  presentationDocumentNew.SaveAs(tmpFilePath);
  presentationDocumentNew.Close();

Question: OpenXml Presentation(PPT-pptx) i don't want to save in physical part. I just want to download file directly from browser using HttpResponse
 I try many way to But its not worked. File downloed but its correpted.
    Try: 1) presentationDocumentNew.PresentationPart.GetStream().CopyTo(Response.OutputStream);
	     2) take Stream or Memory stream or FileStream, set in response
		    Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
          Response.AddHeader("Content-Disposition", "attachment; filename=" + "cccc.pptx");
          ......etc
 Not worked all


What I have tried:

<pre>PresentationDocument presentationDocumentNew = null;


using (PresentationDocument presentationDocument = PresentationDocument.Open(file, false))
                   {
                       presentationDocumentNew = (PresentationDocument)presentationDocument.Clone();
                       presentationDocument.Close();
                   }


if (presentationDocumentNew != null)
                    {

// i replace text in presentationDocumentNew 
// Save file on Physical path - Its worked
//  presentationDocumentNew.SaveAs(tmpFilePath);
//  presentationDocumentNew.Close();

//Question: i don't want to save in physical part. I just want to download file directly from browser using HttpResponse
// I try many way to But its not worked. File downloed but its correpted.
//    Try: 1) presentationDocumentNew.PresentationPart.GetStream().CopyTo(Response.OutputStream);
//	     2) take Stream or Memory stream or FileStream, set in response
//		    Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
//          Response.AddHeader("Content-Disposition", "attachment; filename=" + "cccc.pptx");
//          ......etc
// Not worked all

}
Posted
Updated 18-Nov-19 10:13am

Maybe you can try WebClient, see examples here: https://www.dotnetperls.com/webclient[^]

Or try WebRequest, see example here: How to: Request data by using the WebRequest class | Microsoft Docs[^]
 
Share this answer
 
This solution on StackOverflow[^] is for Word documents, but the same approach will apply here:
C#
var memoryStream = new MemoryStream();

using (FileStream fileStream = File.OpenRead(file))
{
    fileStream.CopyTo(memoryStream);
}

memoryStream.Position = 0;

using (PresentationDocument presentationDocument = PresentationDocument.Open(memoryStream, true))
{
    ... Change the presentation here ...
    
    presentationDocument.Close();
}

memoryStream.Position = 0;

Response.ContentType = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
Response.AddHeader("Content-Disposition", "attachment; filename=" + "cccc.pptx");
memoryStream.CopyTo(Response.OutputStream);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900