Add a New Slide in PowerPoint with C# REST API

Follow this article to add a new slide in PowerPoint with C# REST API. You will learn how to add PowerPoint slides with C# .NET-based API using a .NET-based SDK in the Cloud storage. It will guide you to insert slides at the required index in the existing presentation.

Prerequisite

Steps to Add a Slide with C# REST API

  1. Create the SlidesApi object by setting the user ID and secret for adding a slide
  2. Upload the target presentation to a Cloud storage for inserting a slide
  3. Call the CreateSlide() method by providing the uploaded presentation name and destination slide index
  4. Display the URLs of all the slides after adding a new empty slide
  5. Download and save the output presentation with an additional slide

These steps explain how to add a slide to PowerPoint with C# RESTful Service. Create the SlidesApi object with the required information, upload the source presentation to the Cloud storage, and call the CreateSlide() method with the uploaded file name and target slide index.

Code to Add a Slide in PowerPoint with C# .NET-based API

using Aspose.Slides.Cloud.Sdk;
using Aspose.Slides.Cloud.Sdk.Model;
using System;
using System.IO;
namespace AsposeTestCodes
{
class Program
{
static void Main(string[] args)
{
SlidesApi api = new SlidesApi("User ID", "User Secret");
string fileName = "Sample.pptx";
// Upload the source presentation
FilesUploadResult result = api.UploadFile(fileName,
new MemoryStream(File.ReadAllBytes(fileName)));
// Create a new slide.
var response = api.CreateSlide(fileName, position:2);
// Display list of URLs of each slide
foreach (ResourceUri slide in response.SlideList)
{
Console.WriteLine(slide.Href);
}
// Download the updated presentation
Stream storageRes = api.DownloadFile(fileName);
FileStream fileStream = new FileStream("Output.pptx",
FileMode.Create, FileAccess.Write);
storageRes.CopyTo(fileStream);
}
}
}

This code demonstrates how to add slide on PowerPoint with C# Low Code API. You can set the layout alias by using the type of layout, index, or layout slide name for the new slide. If the uploaded presentation is password protected, provide the password while calling the CreateSlide method.

This article has taught us the process of inserting an empty slide. For deleting a slide, refer to the article on delete PowerPoint slide with C# REST API.

 English