Click or drag to resize

PresentationDocumentSave Method (Object, String)

Saves the presentation to a System.Web.HttpResponse or System.Web.HttpResponseBase output stream or a System.Net.Http.HttpResponseMessage and sets appropriate HTTP response headers (Content-Type and Content-Disposition).

Namespace:  GemBox.Presentation
Assembly:  GemBox.Presentation (in GemBox.Presentation.dll) Version: 21.3.35.1041 (21.3.35.1041)
Syntax
public void Save(
	Object httpResponse,
	string fileName
)

Parameters

httpResponse
Type: SystemObject
System.Web.HttpResponse object that can be retrieved through the Response property of the System.Web.HttpApplication, System.Web.HttpContext, System.Web.UI.Page or System.Web.UI.UserControl classes or System.Web.HttpResponseBase object or System.Net.Http.HttpResponseMessage object.
fileName
Type: SystemString
File name that will be presented in client browser when downloading a file.
Exceptions
ExceptionCondition
InvalidOperationExceptionIf file extension is not specified or not supported. If file extension is not recognized, use Save(Object, String, SaveOptions) method overload instead.
Remarks
Note Note
Supported only if updating the whole page with a postback and not if doing partial-page updates (when you use UpdatePanel controls to update selected regions of a page).

This method accepts Object rather than HttpResponse or HttpResponseBase or HttpResponseMessage because otherwise GemBox.Presentation assembly would have a dependency on System.Web or System.Net.Http assemblies and could not be used in applications which target Client Profile .NET Framework.

HttpResponse can be retrieved through the Response property of the HttpApplication, HttpContext, Page or UserControl classes.

For supported file extensions, see remarks for Save(String) method.

Examples

Following examples show how to stream presentation to a client's browser using various ASP.NET technologies.

ASP.NET Web Forms

Method is defined inside a class that derives from System.Web.UI.Page.

private void ExportPresentation()
{
    // Create a new empty presentation.
    var presentation = new PresentationDocument();

    // Add presentation content.
    presentation.Slides.AddNew(SlideLayoutType.Custom).
        Content.AddTextBox(0, 0, 5, 5, LengthUnit.Centimeter).
        AddParagraph().AddRun("Hello World!");

    HttpResponse response = this.Response;

    // Stream presentation to browser in PPTX format.
    presentation.Save(response, "Presentation.pptx");

}

ASP.NET Web Forms

Method is defined inside a class that derives from System.Web.UI.Page.

private void ExportPresentation()
{
    // Create a new empty presentation.
    var presentation = new PresentationDocument();

    // Add presentation content.
    presentation.Slides.AddNew(SlideLayoutType.Custom).
        Content.AddTextBox(0, 0, 5, 5, LengthUnit.Centimeter).
        AddParagraph().AddRun("Hello World!");

    HttpResponseBase responseBase = new HttpResponseWrapper(this.Response);

    // Stream presentation to browser in PPTX format.
    presentation.Save(responseBase, "Presentation.pptx");
}

ASP.NET MVC

Method is defined inside a class that derives from System.Web.Mvc.Controller.

public ActionResult ExportPresentation()
{
    // Create a new empty presentation.
    var presentation = new PresentationDocument();

    // Add presentation content.
    presentation.Slides.AddNew(SlideLayoutType.Custom).
        Content.AddTextBox(0, 0, 5, 5, LengthUnit.Centimeter).
        AddParagraph().AddRun("Hello World!");

    byte[] fileContents;

    var options = SaveOptions.Pptx;

    // Save presentation to PPTX format in byte array.
    using (var stream = new MemoryStream())
    {
        presentation.Save(stream, options);

        fileContents = stream.ToArray();
    }

    // Stream presentation to browser in PPTX format.
    return File(fileContents, options.ContentType, "Presentation.pptx");
}

ASP.NET Web API

Method is defined inside a class that derives from System.Web.Http.ApiController.

public HttpResponseMessage ExportPresentation()
{
    // Create a new empty presentation.
    var presentation = new PresentationDocument();

    // Add presentation content.
    presentation.Slides.AddNew(SlideLayoutType.Custom).
        Content.AddTextBox(0, 0, 5, 5, LengthUnit.Centimeter).
        AddParagraph().AddRun("Hello World!");

    var responseMessage = new HttpResponseMessage(HttpStatusCode.OK);

    // Save presentation to response message content in PPTX format.
    presentation.Save(responseMessage, "Presentation.pptx");

    return responseMessage;
}
See Also