Spire.Cloud.PowerPoint provides the PropertiesApi interface to handle properties of PowerPoint documents. This article shows you how to add or remove properties by using this API.
Example 1. Add document properties
using System;
using System.Collections.Generic;
using Spire.Cloud.Powerpoint.Sdk.Client;
using Spire.Cloud.Powerpoint.Sdk.Api;
using Spire.Cloud.Powerpoint.Sdk.Model;
namespace SetProperties
{
class Program
{
static String appId = "App ID";
static String appKey = "App Key";
static String baseUrl = " https://api.cloudxdocs.com";
//Create a Configuration object based on App ID, App Key and base URL
static Configuration configuration = new Configuration(appId, appKey, baseUrl);
//Create a PropertiesApi object
static PropertiesApi propertiesApi = new PropertiesApi(configuration);
static void Main(string[] args)
{
//Specify the source document name
string name = "sample.pptx";
//Specify the original password, set to null if there is no password
string password = null;
//Specify the folder where the source document is stored
string folder = "input";
//Use the default storage, set to null
string storage = null;
//Create DocumentProperty objects
DocumentProperty property1 = new DocumentProperty("Title", "Sample", true);
DocumentProperty property2 = new DocumentProperty("Subject", "Document Properties", true);
DocumentProperty property3 = new DocumentProperty("Keywords", "PowerPoint;Property", true);
DocumentProperty property4 = new DocumentProperty("Category", "Spire.Cloud Tutorials", true);
DocumentProperty property5 = new DocumentProperty("Comments", "None", true);
DocumentProperty property6 = new DocumentProperty("Author", "Spire.Cloud.SDK", true);
DocumentProperty property7 = new DocumentProperty("Company", "E-iceblue Co. Ltd.", true);
//Add properties to a list
List propertyList = new List();
propertyList.Add(property1);
propertyList.Add(property2);
propertyList.Add(property3);
propertyList.Add(property4);
propertyList.Add(property5);
propertyList.Add(property6);
propertyList.Add(property7);
//Create a DocumentProperties object based on the list
DocumentProperties properties = new DocumentProperties(propertyList);
//Call SetPptDocumentProperties to add properties to document
propertiesApi.SetPptDocumentProperties(name, properties, password, folder, storage);
}
}
}
Example 2. Remove document properties
using System;
using Spire.Cloud.Powerpoint.Sdk.Client;
using Spire.Cloud.Powerpoint.Sdk.Api;
namespace RemoveProperties
{
class Program
{
static String appId = "App ID";
static String appKey = "App Key";
static String baseUrl = " https://api.cloudxdocs.com";
//Create a Configuration object based on App ID, App Key and base URL
static Configuration configuration = new Configuration(appId, appKey, baseUrl);
//Create a PropertiesApi object
static PropertiesApi propertiesApi = new PropertiesApi(configuration);
static void Main(string[] args)
{
//Specify the source document name
string name = "sample.pptx";
//Specify the open password of the source document, set to null if there’s no password
string password = null;
//Specify the folder where the source document is stored
string folder = "input";
//Use the default storage, set to null
string storage = null;
//Call DeletePptDocumentProperties to remove all properties
propertiesApi.DeletePptDocumentProperties(name, password, folder, storage);
}
}
}