views:

37

answers:

1

I'm generating a PowerPoint file using this as reference. A user can search other users based on many criterias. Information based on the user is saved in the PowerPoint file. But I can't save all PowerPoint files on the server.

So, the user needs to right click a link, choose "Save as", and save the file locally.

Nothing should be saved on the server. I have been googling, but I'm not sure what to look for. Can you please point out a good tutorial?

I seems I am a bad googler. I removed "powerpoint" from my search string, and there are a lot of hits. But still, any comment is appreciated.

Thanks

+1  A: 

You should get file as a stream, open it using open xml sdk (You need to have Open XML SDK: here).

If you are not familiar with Open XML SDK, you can also look at the blog post here which is also taken from the blog you already referenced.

Below code is a sample code how I create report and send to client using Open XML SDK with ASP.NET. I hope it can be helpful.

public void SendReport()
{
    using (Stream stream = GetReportStream())
    {
        stream.Position = 0;
        byte[] buffer = new byte[(int)stream.Length];
        stream.Read(buffer, 0, (int)stream.Length);
        System.Web.HttpContext.Current.Response.Clear();
        System.Web.HttpContext.Current.Response.Buffer = true;
        System.Web.HttpContext.Current.Response.AddHeader("Content-Type", "application/pptx");
        System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=Report;");

        System.Web.HttpContext.Current.Response.BinaryWrite(buffer);
        System.Web.HttpContext.Current.Response.Flush();
        System.Web.HttpContext.Current.Response.Close();
    }
}

private Stream GetReportStream()
{
    MemoryStream stream = new MemoryStream();
    using (FileStream file = File.Open(@"TemplateFileLocation", FileMode.Open))
    {
        byte[] buffer = new byte[file.Length];
        file.Read(buffer, 0, (int)file.Length);
        stream.Write(buffer, 0, buffer.Length);
    }
    using (PresentationDocument presentationDocument = PresentationDocument.Open(stream, true))
    {
        // Doing manipulations explained in your reference document link.

        presentationPart.Presentation.Save();
    }
    return stream;
}

Don't forget to download and check the whole solution on the link you referenced.

Musa Hafalır
Ok, Musa. It looks good. I have combined the code from the url I posted with your suggestion. I need to test a little more, but Im sure I have found what I was looking for. Thank you.......
Mr. Powerpoint
Happy to be helpful. I hope it works.
Musa Hafalır