Over a million developers have joined DZone.

Merge Multiple Presentation by Passing List of All Files in .NET Apps

This technical tip allows developers to merge multiple presentation files   using Saaspose.Slides REST API in your .NET applications. You can pass a list of all the files you want to merge using this example. Developers need to upload all the input files (Presentation1.pptx, Presentation2.pptx and Presentation3.pptx in case of this example) before running this example. Please check Upload File to Saaspose for how to. Some important steps for performing this task are to specify product URI, build URI, build URI to download merged presentation and Save output file.
SaasposeApp.AppKey = "89**********************";
SaasposeApp.AppSID = "77***********************";
//specify product URI
Product.BaseProductUri = @"http://api.saaspose.com/v1.0";

string[] presentationsList = new string[] { "Presentation2.pptx", "Presentation3.pptx" };
PresentationsList list = new PresentationsList();
list.PresentationPaths = presentationsList;

string strJSON = JsonConvert.SerializeObject(list);

//build URI
string strURI = "http://api.saaspose.com/v1.0/slides/Presentation1.pptx/merge"; //Product.BaseProductUri + "/pdf/" + basePdf + "/appendDocument?appendFile=" + newPdf + "&startPage=1&endPage=" + iPageCount.ToString();
string signedURI = Utils.Sign(strURI);

Utils.ProcessCommand(signedURI, "POST", strJSON);

// build URI to download merged presentation
strURI = "http://api.saaspose.com/v1.0/storage/file/Presentation1.pptx";
signedURI = Utils.Sign(strURI);

using (Stream responseStream = Utils.ProcessCommand(signedURI, "GET"))
    //Save output file
    using (Stream fileStream = System.IO.File.OpenWrite("C:\\MergedPresentation.pptx"))
        Utils.CopyStream(responseStream, fileStream);

//Following is the PresentationsList class

/// represents list of presentations to be merged
class PresentationsList
    public PresentationsList() { }

    public string[] PresentationPaths { get; set; }

//build URI to upload file to Saaspose
            string strURI = "http://api.saaspose.com/v1.0/storage/file/MyRemoteFileName";
            string signedURI = Sign(strURI);
            UploadFileBinary(localfilepath, signedURI, "PUT");

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}