Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save groupdocs-cloud-gists/beda62314b46f1fe33fc8de7293aa9cb to your computer and use it in GitHub Desktop.
Save groupdocs-cloud-gists/beda62314b46f1fe33fc8de7293aa9cb to your computer and use it in GitHub Desktop.
// Download Resultant File from the Cloud
using System;
using GroupDocs.Conversion.Cloud.Sdk.Api;
using GroupDocs.Conversion.Cloud.Sdk.Client;
using GroupDocs.Conversion.Cloud.Sdk.Model.Requests;
namespace GroupDocs.Merger.CSharp
{
// Download Output File
class Download_File
{
static void Main(string[] args)
{
try
{
// initialize api
var fileApi = new FileApi(configuration);
// create download file request
var downloadRequest = new DownloadFileRequest("csharp-testing/merged-file.pptx", myStorage);
// download file
Stream downloadResponse = fileApi.DownloadFile(downloadRequest);
// save file in working directory
using (var fileStream = System.IO.File.Create("H:\\groupdocs-cloud-data\\merged-file.pptx"))
{
downloadResponse.Seek(0, SeekOrigin.Begin);
downloadResponse.CopyTo(fileStream);
}
}
catch (Exception e)
{
Console.WriteLine("Exception when calling GroupDocs FileApi: " + e.Message);
}
}
}
}

You can combine powerpoint slides from different files programmatically on the cloud. In this article, you will learn how to merge and combine PowerPoint PPT/PPTX presentations in C#

The following topics are covered in this article:

  1. PowerPoint Merger REST API and C# SDK
  2. Merge Multiple PPT/PPTX Files into One in C# using REST API
  3. Merge Specific Slides of Multiple PowerPoint Files in C#
  4. Combine PowerPoint Presentations in C# using Slides Range
// How to Combine PowerPoint Presentations in C# using Slides Range
using System;
using GroupDocs.Merger.Cloud.Sdk.Api;
using GroupDocs.Merger.Cloud.Sdk.Client;
using GroupDocs.Merger.Cloud.Sdk.Model;
using GroupDocs.Merger.Cloud.Sdk.Model.Requests;
using System.Collections.Generic;
namespace GroupDocs.Merger.CSharp
{
// Merge and Combine PPT files into one PPT
class Merge_PowerPoint_Files
{
static void Main(string[] args)
{
try
{
// Create necessary API instances
var documentApi = new DocumentApi(configuration);
var item1 = new JoinItem
{
FileInfo = new GroupDocs.Merger.Cloud.Sdk.Model.FileInfo
{
FilePath = "csharp-testing/input-sample-file-one.pptx"
}
};
var item2 = new JoinItem
{
FileInfo = new GroupDocs.Merger.Cloud.Sdk.Model.FileInfo
{
FilePath = "csharp-testing/input-sample-file-two.pptx"
},
StartPageNumber = 1,
EndPageNumber = 5,
RangeMode = JoinItem.RangeModeEnum.OddPages
};
var options = new JoinOptions
{
JoinItems = new List<JoinItem> { item1, item2 },
OutputPath = "csharp-testing/merged-file.pptx"
};
var request = new JoinRequest(options);
var response = documentApi.Join(request);
Console.WriteLine("Successfully combined PowerPoint slides from different files: " + response.Path);
}
catch (Exception e)
{
Console.WriteLine("Exception when calling GroupDocs Api: " + e.Message);
}
}
}
}
// How to Merge Specific Slides of Multiple PowerPoint Files in C#
using System;
using GroupDocs.Merger.Cloud.Sdk.Api;
using GroupDocs.Merger.Cloud.Sdk.Client;
using GroupDocs.Merger.Cloud.Sdk.Model;
using GroupDocs.Merger.Cloud.Sdk.Model.Requests;
using System.Collections.Generic;
namespace GroupDocs.Merger.CSharp
{
// Combine PPTX slides into one PPT
class Merge_PowerPoint_Files
{
static void Main(string[] args)
{
try
{
// Create necessary API instances
var documentApi = new DocumentApi(configuration);
var item1 = new JoinItem
{
FileInfo = new GroupDocs.Merger.Cloud.Sdk.Model.FileInfo
{
FilePath = "csharp-testing/input-sample-file-one.pptx"
},
Pages = new List<int?> { 1, 4, 7 }
};
var item2 = new JoinItem
{
FileInfo = new GroupDocs.Merger.Cloud.Sdk.Model.FileInfo
{
FilePath = "csharp-testing/input-sample-file-two.pptx"
},
StartPageNumber = 1,
EndPageNumber = 5,
RangeMode = JoinItem.RangeModeEnum.OddPages
};
var options = new JoinOptions
{
JoinItems = new List<JoinItem> { item1, item2 },
OutputPath = "csharp-testing/merged-file.pptx"
};
var request = new JoinRequest(options);
var response = documentApi.Join(request);
Console.WriteLine("Successfully combine several powerpoints into one using CSharp: " + response.Path);
}
catch (Exception e)
{
Console.WriteLine("Exception when calling GroupDocs Api: " + e.Message);
}
}
}
}
// How to Merge Multiple PPT/PPTX Files into One in C# using REST API
using System;
using GroupDocs.Merger.Cloud.Sdk.Api;
using GroupDocs.Merger.Cloud.Sdk.Client;
using GroupDocs.Merger.Cloud.Sdk.Model;
using GroupDocs.Merger.Cloud.Sdk.Model.Requests;
namespace GroupDocs.Merger.CSharp
{
// How to Merge PowerPoint Files into One using CSharp
class Combine_PowerPoint_Presentations
{
static void Main(string[] args)
{
try
{
// Create necessary API instances
var documentApi = new DocumentApi(configuration);
var item1 = new JoinItem
{
FileInfo = new GroupDocs.Merger.Cloud.Sdk.Model.FileInfo
{
FilePath = "csharp-testing/two-slides-file.pptx"
}
};
var item2 = new JoinItem
{
FileInfo = new GroupDocs.Merger.Cloud.Sdk.Model.FileInfo
{
FilePath = "csharp-testing/one-slide-file.pptx"
}
};
var options = new JoinOptions
{
JoinItems = new List<JoinItem> { item1, item2 },
OutputPath = "csharp-testing/merged-file.pptx"
};
var request = new JoinRequest(options);
var response = documentApi.Join(request);
Console.WriteLine("Successfully merged PowerPoint PPTX slides online using REST API: " + response.Path);
}
catch (Exception e)
{
Console.WriteLine("Exception when calling GroupDocs Api: " + e.Message);
}
}
}
}
// Upload Files using C#
using System;
using System.IO;
using GroupDocs.Merger.Cloud.Sdk.Api;
using GroupDocs.Merger.Cloud.Sdk.Client;
using GroupDocs.Merger.Cloud.Sdk.Model;
using GroupDocs.Merger.Cloud.Sdk.Model.Requests;
namespace GroupDocs.Merger.CSharp
{
class Upload_PowerPoint_Presentations
{
static void Main(string[] args)
{
try
{
// Create necessary API instances
var storageApi = new StorageApi(configuration);
var fileApi = new FileApi(configuration);
var path = @"H:\groupdocs-cloud-data";
var files = Directory.GetFiles(path, "*.pptx", SearchOption.AllDirectories);
foreach (var file in files)
{
var relativeFilePath = file.Replace(path, string.Empty).Trim(Path.DirectorySeparatorChar);
var response = storageApi.ObjectExists(new ObjectExistsRequest(relativeFilePath, myStorage));
if (response.Exists != null && !response.Exists.Value)
{
var fileStream = File.Open(file, FileMode.Open);
fileApi.UploadFile(new UploadFileRequest(relativeFilePath, fileStream, myStorage));
fileStream.Close();
}
}
Console.WriteLine("File Uploaded to Cloud Storage.");
}
catch (Exception e)
{
Console.WriteLine("Exception when calling GroupDocs API: " + e.Message);
}
}
}
}
//Get clientId & clientSecret from https://dashboard.groupdocs.cloud (free registration is required).
string clientId = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
string clientSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
string myStorage = "test-internal-storage";
var configuration = new Configuration(clientId, clientSecret);
configuration.ApiBaseUrl = "https://api.groupdocs.cloud";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment