Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Merger-CSharp-v2
string MyClientId = "YOUR-CLIENT-ID";
string MyClientSecret = "YOUR-CLIENT-SECRET";
string MyStorage;
var storageConfig = new Configuration(MyClientId, MyClientSecret);
var documentApi = new DocumentApi(storageConfig);
var storageApi = new StorageApi(storageConfig);
var fileApi = new FileApi(storageConfig);
using GroupDocs.Merger.Cloud.Sdk.Api;
using GroupDocs.Merger.Cloud.Sdk.Client;
using GroupDocs.Merger.Cloud.Sdk.Model.Requests;
using System;
using GroupDocs.Merger.Cloud.Sdk.Model;
using FileInfo = GroupDocs.Merger.Cloud.Sdk.Model.FileInfo;
namespace GroupDocs.Merger.Cloud.Examples.CSharp
{
/// <summary>
/// This example demonstrates how to add password to document.
/// </summary>
public class AddDocumentPassword
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new SecurityApi(configuration);
try
{
var fileInfo = new FileInfo
{
FilePath = "WordProcessing/one-page.docx",
Password = "Password"
};
var options = new Options
{
FileInfo = fileInfo,
OutputPath = "output/add-password.docx"
};
var request = new AddPasswordRequest(options);
var response = apiInstance.AddPassword(request);
Console.WriteLine("Output file path: " + response.Path);
}
catch (Exception e)
{
Console.WriteLine("Exception while calling api: " + e.Message);
}
}
}
}
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;
using System.Collections.Generic;
using FileInfo = GroupDocs.Merger.Cloud.Sdk.Model.FileInfo;
namespace GroupDocs.Merger.Cloud.Examples.CSharp
{
/// <summary>
/// This example demonstrates how to change document page orientation.
/// </summary>
public class ChangePageOrientation
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new PagesApi(configuration);
try
{
var fileInfo = new FileInfo
{
FilePath = "WordProcessing/four-pages.docx"
};
var options = new OrientationOptions
{
FileInfo = fileInfo,
OutputPath = "Output/change-page-orientation.docx",
Pages = new List<int?> { 2, 4 },
Mode = OrientationOptions.ModeEnum.Landscape
};
var request = new OrientationRequest(options);
var response = apiInstance.Orientation(request);
Console.WriteLine("Output file path: " + response.Path);
}
catch (Exception e)
{
Console.WriteLine("Exception while calling api: " + e.Message);
}
}
}
}
using GroupDocs.Merger.Cloud.Sdk.Api;
using GroupDocs.Merger.Cloud.Sdk.Client;
using GroupDocs.Merger.Cloud.Sdk.Model.Requests;
using System;
using FileInfo = GroupDocs.Merger.Cloud.Sdk.Model.FileInfo;
namespace GroupDocs.Merger.Cloud.Examples.CSharp
{
/// <summary>
/// This example demonstrates how to check document password.
/// </summary>
public class CheckDocumentPasswordProtection
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new SecurityApi(configuration);
try
{
var fileInfo = new FileInfo
{
FilePath = "WordProcessing/password-protected.docx"
};
var request = new CheckPasswordRequest(fileInfo.FilePath);
var response = apiInstance.CheckPassword(request);
Console.WriteLine("Check password: " + response.IsPasswordSet);
}
catch (Exception e)
{
Console.WriteLine("Exception while calling api: " + e.Message);
}
}
}
}
using System.IO;
using System;
using GroupDocs.Merger.Cloud.Sdk.Api;
using GroupDocs.Merger.Cloud.Sdk.Client;
namespace GroupDocs.Merger.Cloud.Examples.CSharp
{
internal class Common
{
public static string MyAppSid;
public static string MyAppKey;
public static string MyStorage;
public static void UploadSampleTestFiles()
{
var storageConfig = new Configuration(MyAppSid, MyAppKey);
var storageApi = new StorageApi(storageConfig);
var folderApi = new FolderApi(storageConfig);
var fileApi = new FileApi(storageConfig);
var path = "..\\..\\..\\Resources";
Console.WriteLine("File Upload Processing...");
var dirs = Directory.GetDirectories(path, "*", SearchOption.AllDirectories);
foreach (var dir in dirs)
{
var relativeDirPath = dir.Replace(path, string.Empty).Trim(Path.DirectorySeparatorChar);
var response = storageApi.ObjectExists(new Sdk.Model.Requests.ObjectExistsRequest(relativeDirPath, MyStorage));
if (response.Exists != null && !response.Exists.Value)
{
folderApi.CreateFolder(new Sdk.Model.Requests.CreateFolderRequest(relativeDirPath, MyStorage));
}
}
var files = Directory.GetFiles(path, "*", SearchOption.AllDirectories);
foreach (var file in files)
{
var relativeFilePath = file.Replace(path, string.Empty).Trim(Path.DirectorySeparatorChar);
var response = storageApi.ObjectExists(new Sdk.Model.Requests.ObjectExistsRequest(relativeFilePath, MyStorage));
if (response.Exists != null && !response.Exists.Value)
{
var fileStream = File.Open(file, FileMode.Open);
fileApi.UploadFile(new Sdk.Model.Requests.UploadFileRequest(relativeFilePath, fileStream, MyStorage));
fileStream.Close();
}
}
Console.WriteLine("File Upload Process Completed.");
}
}
}
using GroupDocs.Merger.Cloud.Sdk.Api;
using GroupDocs.Merger.Cloud.Sdk.Client;
using GroupDocs.Merger.Cloud.Sdk.Model.Requests;
using System;
namespace GroupDocs.Merger.Cloud.Examples.CSharp
{
// Copy File
class Copy_File
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new FileApi(configuration);
try
{
var request = new CopyFileRequest("WordProcessing/one-page.docx", "WordProcessing/one-page-copied.docx", Common.MyStorage, Common.MyStorage);
apiInstance.CopyFile(request);
Console.WriteLine("Expected response type is Void: 'WordProcessing/one-page.docx' file copied as 'WordProcessing/one-page-copied.docx'.");
}
catch (Exception e)
{
Console.WriteLine("Exception while calling FileApi: " + e.Message);
}
}
}
}
using System;
using GroupDocs.Merger.Cloud.Sdk.Api;
using GroupDocs.Merger.Cloud.Sdk.Client;
using GroupDocs.Merger.Cloud.Sdk.Model.Requests;
namespace GroupDocs.Merger.Cloud.Examples.CSharp
{
// Copy Folder
class Copy_Folder
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new FolderApi(configuration);
try
{
var request = new CopyFolderRequest("WordProcessing", "WordProcessing1", Common.MyStorage, Common.MyStorage);
apiInstance.CopyFolder(request);
Console.WriteLine("Expected response type is Void: 'WordProcessing' folder copied as 'WordProcessing1'.");
}
catch (Exception e)
{
Console.WriteLine("Exception while calling FolderApi: " + e.Message);
}
}
}
}
using System;
using GroupDocs.Merger.Cloud.Sdk.Api;
using GroupDocs.Merger.Cloud.Sdk.Client;
using GroupDocs.Merger.Cloud.Sdk.Model.Requests;
namespace GroupDocs.Merger.Cloud.Examples.CSharp
{
// Create Folder
class Create_Folder
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new FolderApi(configuration);
try
{
var request = new CreateFolderRequest("", Common.MyStorage);
apiInstance.CreateFolder(request);
Console.WriteLine("Expected response type is Void: 'WordProcessing' folder created.");
}
catch (Exception e)
{
Console.WriteLine("Exception while calling FolderApi: " + e.Message);
}
}
}
}
using GroupDocs.Merger.Cloud.Sdk.Api;
using GroupDocs.Merger.Cloud.Sdk.Client;
using GroupDocs.Merger.Cloud.Sdk.Model.Requests;
using System;
namespace GroupDocs.Merger.Cloud.Examples.CSharp
{
// Delete File
class Delete_File
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new FileApi(configuration);
try
{
var request = new DeleteFileRequest("WordProcessing1/one-page.docx", Common.MyStorage);
apiInstance.DeleteFile(request);
Console.WriteLine("Expected response type is Void: 'WordProcessing1/one-page.docx' deleted.");
}
catch (Exception e)
{
Console.WriteLine("Exception while calling FileApi: " + e.Message);
}
}
}
}
using System;
using GroupDocs.Merger.Cloud.Sdk.Api;
using GroupDocs.Merger.Cloud.Sdk.Client;
using GroupDocs.Merger.Cloud.Sdk.Model.Requests;
namespace GroupDocs.Merger.Cloud.Examples.CSharp
{
// Delete Folder
class Delete_Folder
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new FolderApi(configuration);
try
{
var request = new DeleteFolderRequest("WordProcessing/WordProcessing1", Common.MyStorage, true);
apiInstance.DeleteFolder(request);
Console.WriteLine("Expected response type is Void: 'WordProcessing/WordProcessing1' folder deleted recusrsively.");
}
catch (Exception e)
{
Console.WriteLine("Exception while calling FolderApi: " + e.Message);
}
}
}
}
using GroupDocs.Merger.Cloud.Sdk.Api;
using GroupDocs.Merger.Cloud.Sdk.Client;
using GroupDocs.Merger.Cloud.Sdk.Model.Requests;
using System;
using System.IO;
namespace GroupDocs.Merger.Cloud.Examples.CSharp
{
// Download_File
class Download_File
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new FileApi(configuration);
try
{
var request = new DownloadFileRequest("WordProcessing/ten-pages.pdf", Common.MyStorage);
Stream response = apiInstance.DownloadFile(request);
using (var fileStream = File.Create("D:\\tenpages.pdf"))
{
response.Seek(0, SeekOrigin.Begin);
response.CopyTo(fileStream);
}
Console.WriteLine("Expected response type is Stream: " + response.Length.ToString());
}
catch (Exception e)
{
Console.WriteLine("Exception while calling FileApi: " + e.Message);
}
}
}
}
public static void DownloadFiles(FileApi fileApi, string file)
{
try
{
var downloadRequest = new DownloadFileRequest(file, MyStorage);
Stream downloadResponse = fileApi.DownloadFile(downloadRequest);
using (var fileStream = File.Create("C:\\Files\\" + file))
{
downloadResponse.Seek(0, SeekOrigin.Begin);
downloadResponse.CopyTo(fileStream);
}
Console.WriteLine("File downloaded successfully");
}
catch (Exception e)
{
Console.WriteLine("Exception while calling api: " + e.Message);
}
}
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;
using System.Collections.Generic;
using FileInfo = GroupDocs.Merger.Cloud.Sdk.Model.FileInfo;
namespace GroupDocs.Merger.Cloud.Examples.CSharp
{
/// <summary>
/// This example demonstrates how to extract document pages by specifying their numbers.
/// </summary>
public class ExtractPagesByNumbers
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new PagesApi(configuration);
try
{
var fileInfo = new FileInfo
{
FilePath = "WordProcessing/sample-10-pages.docx"
};
var options = new ExtractOptions
{
FileInfo = fileInfo,
OutputPath = "Output/extract-pages-by-numbers.docx",
Pages = new List<int?> { 2, 4, 7 }
};
var request = new ExtractRequest(options);
var response = apiInstance.Extract(request);
Console.WriteLine("Output file path: " + response.Path);
}
catch (Exception e)
{
Console.WriteLine("Exception while calling api: " + e.Message);
}
}
}
}
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;
using System.Collections.Generic;
using FileInfo = GroupDocs.Merger.Cloud.Sdk.Model.FileInfo;
namespace GroupDocs.Merger.Cloud.Examples.CSharp
{
/// <summary>
/// This example demonstrates how to extract document pages by specifying page numbers range.
/// </summary>
public class ExtractPagesByRange
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new PagesApi(configuration);
try
{
var fileInfo = new FileInfo
{
FilePath = "WordProcessing/sample-10-pages.docx"
};
var options = new ExtractOptions
{
FileInfo = fileInfo,
OutputPath = "Output/extract-pages-by-range.docx",
StartPageNumber = 1,
EndPageNumber = 10,
RangeMode = PageOptions.RangeModeEnum.EvenPages
};
var request = new ExtractRequest(options);
var response = apiInstance.Extract(request);
Console.WriteLine("Output file path: " + response.Path);
}
catch (Exception e)
{
Console.WriteLine("Exception while calling api: " + e.Message);
}
}
}
}
using System;
using GroupDocs.Merger.Cloud.Sdk.Api;
using GroupDocs.Merger.Cloud.Sdk.Client;
using GroupDocs.Merger.Cloud.Sdk.Model.Requests;
namespace GroupDocs.Merger.Cloud.Examples.CSharp
{
// Get Get Disc Usage
class Get_Disc_Usage
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new StorageApi(configuration);
try
{
var request = new GetDiscUsageRequest(Common.MyStorage);
var response = apiInstance.GetDiscUsage(request);
Console.WriteLine("Expected response type is DiscUsage: " + response.UsedSize.ToString());
}
catch (Exception e)
{
Console.WriteLine("Exception while calling StorageApi: " + e.Message);
}
}
}
}
using System;
using GroupDocs.Merger.Cloud.Sdk.Api;
using GroupDocs.Merger.Cloud.Sdk.Client;
using GroupDocs.Merger.Cloud.Sdk.Model.Requests;
namespace GroupDocs.Merger.Cloud.Examples.CSharp
{
// Get File Versions
class Get_File_Versions
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new StorageApi(configuration);
try
{
var request = new GetFileVersionsRequest("one-page.docx", Common.MyStorage);
var response = apiInstance.GetFileVersions(request);
Console.WriteLine("Expected response type is FileVersions: " + response.Value.Count.ToString());
}
catch (Exception e)
{
Console.WriteLine("Exception while calling StorageApi: " + e.Message);
}
}
}
}
using System;
using GroupDocs.Merger.Cloud.Sdk.Api;
using GroupDocs.Merger.Cloud.Sdk.Client;
using GroupDocs.Merger.Cloud.Sdk.Model.Requests;
namespace GroupDocs.Merger.Cloud.Examples.CSharp
{
// Get Files List
class Get_Files_List
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new FolderApi(configuration);
try
{
var request = new GetFilesListRequest("WordProcessing", Common.MyStorage);
var response = apiInstance.GetFilesList(request);
Console.WriteLine("Expected response type is FilesList: " + response.Value.Count.ToString());
}
catch (Exception e)
{
Console.WriteLine("Exception while calling FolderApi: " + e.Message);
}
}
}
}
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;
namespace GroupDocs.Merger.Cloud.Examples.CSharp
{
/// <summary>
/// This example demonstrates how to get document info.
/// </summary>
public class GetDocumentInformation
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new InfoApi(configuration);
try
{
var fileInfo = new FileInfo
{
FilePath = "WordProcessing/password-protected.docx",
Password = "password",
StorageName = Common.MyStorage
};
var request = new GetInfoRequest(fileInfo);
var response = apiInstance.GetInfo(request);
Console.WriteLine("InfoResult.Pages.Count: " + response.Pages.Count);
}
catch (Exception e)
{
Console.WriteLine("Exception while calling InfoApi: " + e.Message);
}
}
}
}
using GroupDocs.Merger.Cloud.Sdk.Api;
using GroupDocs.Merger.Cloud.Sdk.Client;
using System;
namespace GroupDocs.Merger.Cloud.Examples.CSharp
{
/// <summary>
/// This example demonstrates how to obtain all supported file types.
/// </summary>
public class GetSupportedFileTypes
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new InfoApi(configuration);
try
{
// Get supported file formats
var response = apiInstance.GetSupportedFileFormats();
foreach (var entry in response.Formats)
{
Console.WriteLine($"{entry.FileFormat}: {string.Join(",", entry.Extension)}");
}
}
catch (Exception e)
{
Console.WriteLine("Exception while calling InfoApi: " + e.Message);
}
}
}
}
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;
using System.Collections.Generic;
using FileInfo = GroupDocs.Merger.Cloud.Sdk.Model.FileInfo;
namespace GroupDocs.Merger.Cloud.Examples.CSharp
{
/// <summary>
/// This example demonstrates how to join multiple documents into one document.
/// </summary>
public class JoinMultipleDocuments
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new DocumentApi(configuration);
try
{
var item1 = new JoinItem
{
FileInfo = new FileInfo
{
FilePath = "WordProcessing/four-pages.docx"
}
};
var item2 = new JoinItem
{
FileInfo = new FileInfo
{
FilePath = "WordProcessing/one-page.docx"
}
};
var options = new JoinOptions
{
JoinItems = new List<JoinItem> { item1, item2 },
OutputPath = "Output/joined.docx"
};
var request = new JoinRequest(options);
var response = apiInstance.Join(request);
Console.WriteLine("Output file path: " + response.Path);
}
catch (Exception e)
{
Console.WriteLine("Exception while calling api: " + e.Message);
}
}
}
}
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;
using System.Collections.Generic;
using FileInfo = GroupDocs.Merger.Cloud.Sdk.Model.FileInfo;
namespace GroupDocs.Merger.Cloud.Examples.CSharp
{
/// <summary>
/// This example demonstrates how to join specific pages from several source documents.
/// </summary>
public class JoinPagesFromVariousDocuments
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new DocumentApi(configuration);
try
{
var item1 = new JoinItem
{
FileInfo = new FileInfo
{
FilePath = "WordProcessing/sample-10-pages.docx"
},
Pages = new List<int?> { 3, 6, 8 }
};
var item2 = new JoinItem
{
FileInfo = new FileInfo
{
FilePath = "WordProcessing/four-pages.docx"
},
StartPageNumber= 1,
EndPageNumber = 4,
RangeMode = JoinItem.RangeModeEnum.OddPages
};
var options = new JoinOptions
{
JoinItems = new List<JoinItem> { item1, item2 },
OutputPath = "Output/joined-pages.docx"
};
var request = new JoinRequest(options);
var response = apiInstance.Join(request);
Console.WriteLine("Output file path: " + response.Path);
}
catch (Exception e)
{
Console.WriteLine("Exception while calling api: " + e.Message);
}
}
}
}
public static void MergeMultipleFiles(DocumentApi documentApi, FileApi fileApi)
{
try
{
var item1 = new JoinItem
{
FileInfo = new GroupDocs.Merger.Cloud.Sdk.Model.FileInfo
{
FilePath = "one-page.pdf"
}
};
var item2 = new JoinItem
{
FileInfo = new GroupDocs.Merger.Cloud.Sdk.Model.FileInfo
{
FilePath = "second-page.pdf"
}
};
var options = new JoinOptions
{
JoinItems = new List<JoinItem> { item1, item2 },
OutputPath = "merged-files.pdf"
};
var request = new JoinRequest(options);
var response = documentApi.Join(request);
Console.WriteLine("Output file path: " + response.Path);
// Download the Merged File
DownloadFiles(fileApi, "merged-files.pdf");
}
catch (Exception e)
{
Console.WriteLine("Exception while calling api: " + e.Message);
}
}
public static void MergeSpecificPagesOfFiles(DocumentApi documentApi, FileApi fileApi)
{
try
{
var item1 = new JoinItem
{
FileInfo = new GroupDocs.Merger.Cloud.Sdk.Model.FileInfo
{
FilePath = "sample-10-pages.pdf"
},
};
var item2 = new JoinItem
{
FileInfo = new GroupDocs.Merger.Cloud.Sdk.Model.FileInfo
{
FilePath = "four-pages.pdf"
},
StartPageNumber = 1,
EndPageNumber = 3,
RangeMode = JoinItem.RangeModeEnum.OddPages
};
var options = new JoinOptions
{
JoinItems = new List<JoinItem> { item1, item2 },
OutputPath = "merged-pages.pdf"
};
var request = new JoinRequest(options);
var response = documentApi.Join(request);
Console.WriteLine("Output file path: " + response.Path);
// Download the Merged File
DownloadFiles(fileApi, "merged-pages.pdf");
}
catch (Exception e)
{
Console.WriteLine("Exception while calling api: " + e.Message);
}
}
using GroupDocs.Merger.Cloud.Sdk.Api;
using GroupDocs.Merger.Cloud.Sdk.Client;
using GroupDocs.Merger.Cloud.Sdk.Model.Requests;
using System;
namespace GroupDocs.Merger.Cloud.Examples.CSharp
{
// Move File
class Move_File
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new FileApi(configuration);
try
{
var request = new MoveFileRequest("WordProcessing/one-page.docx", "WordProcessing1/one-page.docx", Common.MyStorage, Common.MyStorage);
apiInstance.MoveFile(request);
Console.WriteLine("Expected response type is Void: 'WordProcessing/one-page.docx' file moved to 'WordProcessing1/one-page.docx'.");
}
catch (Exception e)
{
Console.WriteLine("Exception while calling FileApi: " + e.Message);
}
}
}
}
using GroupDocs.Merger.Cloud.Sdk.Api;
using GroupDocs.Merger.Cloud.Sdk.Client;
using GroupDocs.Merger.Cloud.Sdk.Model.Requests;
using System;
namespace GroupDocs.Merger.Cloud.Examples.CSharp
{
// Move Folder
class Move_Folder
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new FolderApi(configuration);
try
{
var request = new MoveFolderRequest("WordProcessing1", "WordProcessing\\WordProcessing1", Common.MyStorage, Common.MyStorage);
apiInstance.MoveFolder(request);
Console.WriteLine("Expected response type is Void: 'WordProcessing1' folder moved to 'WordProcessing/WordProcessing1'.");
}
catch (Exception e)
{
Console.WriteLine("Exception while calling FolderApi: " + e.Message);
}
}
}
}
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;
using FileInfo = GroupDocs.Merger.Cloud.Sdk.Model.FileInfo;
namespace GroupDocs.Merger.Cloud.Examples.CSharp
{
/// <summary>
/// This example demonstrates how to move document page to a new position.
/// </summary>
public class MovePage
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new PagesApi(configuration);
try
{
var fileInfo = new FileInfo
{
FilePath = "WordProcessing/four-pages.docx"
};
var options = new MoveOptions
{
FileInfo = fileInfo,
OutputPath = "Output/move-pages.docx",
PageNumber = 1,
NewPageNumber = 2
};
var request = new MoveRequest(options);
var response = apiInstance.Move(request);
Console.WriteLine("Output file path: " + response.Path);
}
catch (Exception e)
{
Console.WriteLine("Exception while calling api: " + e.Message);
}
}
}
}
using System;
using GroupDocs.Merger.Cloud.Sdk.Api;
using GroupDocs.Merger.Cloud.Sdk.Client;
using GroupDocs.Merger.Cloud.Sdk.Model.Requests;
namespace GroupDocs.Merger.Cloud.Examples.CSharp
{
// Is Object Exists
class Object_Exists
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new StorageApi(configuration);
try
{
var request = new ObjectExistsRequest("WordProcessing/one-page.docx", Common.MyStorage);
var response = apiInstance.ObjectExists(request);
Console.WriteLine("Expected response type is ObjectExist: " + response.Exists.Value.ToString());
}
catch (Exception e)
{
Console.WriteLine("Exception while calling StorageApi: " + e.Message);
}
}
}
}
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;
using System.Collections.Generic;
using FileInfo = GroupDocs.Merger.Cloud.Sdk.Model.FileInfo;
namespace GroupDocs.Merger.Cloud.Examples.CSharp
{
/// <summary>
/// This example demonstrates how to generate document pages preview.
/// </summary>
public class PreviewDocument
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new DocumentApi(configuration);
try
{
var fileInfo = new FileInfo
{
FilePath = "WordProcessing/four-pages.docx"
};
var options = new PreviewOptions()
{
FileInfo = fileInfo,
OutputPath = "Output/preview-page",
Pages = new List<int?> { 1, 3 },
Format = PreviewOptions.FormatEnum.Png
};
var request = new PreviewRequest(options);
var response = apiInstance.Preview(request);
foreach (var document in response.Documents)
{
Console.WriteLine("Output file path: " + document.Path);
}
}
catch (Exception e)
{
Console.WriteLine("Exception while calling api: " + e.Message);
}
}
}
}
using GroupDocs.Merger.Cloud.Sdk.Api;
using GroupDocs.Merger.Cloud.Sdk.Client;
using GroupDocs.Merger.Cloud.Sdk.Model.Requests;
using System;
using GroupDocs.Merger.Cloud.Sdk.Model;
using FileInfo = GroupDocs.Merger.Cloud.Sdk.Model.FileInfo;
namespace GroupDocs.Merger.Cloud.Examples.CSharp
{
/// <summary>
/// This example demonstrates how to remove document password.
/// </summary>
public class RemoveDocumentPassword
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new SecurityApi(configuration);
try
{
var fileInfo = new FileInfo
{
FilePath = "WordProcessing/password-protected.docx",
Password = "password"
};
var options = new Options
{
FileInfo = fileInfo,
OutputPath = "output/remove-password.docx"
};
var request = new RemovePasswordRequest(options);
var response = apiInstance.RemovePassword(request);
Console.WriteLine("Output file path: " + response.Path);
}
catch (Exception e)
{
Console.WriteLine("Exception while calling api: " + e.Message);
}
}
}
}
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;
using System.Collections.Generic;
using FileInfo = GroupDocs.Merger.Cloud.Sdk.Model.FileInfo;
namespace GroupDocs.Merger.Cloud.Examples.CSharp
{
/// <summary>
/// This example demonstrates how to remove document pages.
/// </summary>
public class RemovePages
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new PagesApi(configuration);
try
{
var fileInfo = new FileInfo
{
FilePath = "WordProcessing/four-pages.docx"
};
var options = new RemoveOptions
{
FileInfo = fileInfo,
OutputPath = "Output/remove-pages.docx",
Pages = new List<int?> { 2, 4 }
};
var request = new RemoveRequest(options);
var response = apiInstance.Remove(request);
Console.WriteLine("Output file path: " + response.Path);
}
catch (Exception e)
{
Console.WriteLine("Exception while calling api: " + e.Message);
}
}
}
}
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;
using System.Collections.Generic;
using FileInfo = GroupDocs.Merger.Cloud.Sdk.Model.FileInfo;
namespace GroupDocs.Merger.Cloud.Examples.CSharp
{
/// <summary>
/// This example demonstrates how to rotate document pages.
/// </summary>
public class RotatePages
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new PagesApi(configuration);
try
{
var fileInfo = new FileInfo
{
FilePath = "Pdf/ten-pages.pdf"
};
var options = new RotateOptions
{
FileInfo = fileInfo,
OutputPath = "Output/rotate-pages.pdf",
Pages = new List<int?> { 2, 4 },
Mode = RotateOptions.ModeEnum.Rotate90
};
var request = new RotateRequest(options);
var response = apiInstance.Rotate(request);
Console.WriteLine("Output file path: " + response.Path);
}
catch (Exception e)
{
Console.WriteLine("Exception while calling api: " + e.Message);
}
}
}
}
using System;
namespace GroupDocs.Merger.Cloud.Examples.CSharp
{
public class RunExamples
{
public static void Main(string[] args)
{
//// ***********************************************************
//// GroupDocs.Merger Cloud API Examples
//// ***********************************************************
//TODO: Get your AppSID and AppKey at https://dashboard.groupdocs.cloud (free registration is required).
Common.MyAppSid = "XXXXX-XXXXX-XXXXX-XXXXX-XXXXX";
Common.MyAppKey = "XXXXXXXXXXXXXXXXXXXX";
Common.MyStorage = "XXXXXXXXXX";
// Uploading sample test files from local disk to cloud storage
Common.UploadSampleTestFiles();
#region Working with Storages
#region Working with Storage
Storage_Exist.Run();
Get_Disc_Usage.Run();
Get_File_Versions.Run();
Object_Exists.Run();
#endregion
#region Working with Forlders
Create_Folder.Run();
Copy_Folder.Run();
Move_Folder.Run();
Delete_Folder.Run();
Get_Files_List.Run();
#endregion
#region Working with Files
Upload_File.Run();
Copy_File.Run();
Move_File.Run();
Delete_File.Run();
Download_File.Run();
#endregion
#endregion
#region Get all supported file types
GetSupportedFileTypes.Run();
#endregion
#region Get info for the selected document
GetDocumentInformation.Run();
#endregion
#region Document operations
JoinMultipleDocuments.Run();
JoinPagesFromVariousDocuments.Run();
PreviewDocument.Run();
SplitToSinglePages.Run();
SplitToSinglePagesByRange.Run();
SplitToSinglePagesByRangeWithFilter.Run();
SplitToMultiPageDocuments.Run();
#endregion
#region Pages operations
ChangePageOrientation.Run();
ExtractPagesByNumbers.Run();
ExtractPagesByRange.Run();
MovePage.Run();
RemovePages.Run();
RotatePages.Run();
SwapPages.Run();
#endregion
#region Security operations
AddDocumentPassword.Run();
CheckDocumentPasswordProtection.Run();
RemoveDocumentPassword.Run();
UpdateDocumentPassword.Run();
#endregion
Console.WriteLine("Completed!");
Console.ReadKey();
}
}
}
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;
using System.Collections.Generic;
using FileInfo = GroupDocs.Merger.Cloud.Sdk.Model.FileInfo;
namespace GroupDocs.Merger.Cloud.Examples.CSharp
{
/// <summary>
/// This example demonstrates how to split the document to several multi-page documents by specified page ranges.
/// </summary>
public class SplitToMultiPageDocuments
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new DocumentApi(configuration);
try
{
var fileInfo = new FileInfo
{
FilePath = "WordProcessing/sample-10-pages.docx"
};
var options = new SplitOptions
{
FileInfo = fileInfo,
OutputPath = "Output/split-to-multipage-document",
Pages = new List<int?> { 3, 6, 8 },
Mode = SplitOptions.ModeEnum.Intervals
};
var request = new SplitRequest(options);
var response = apiInstance.Split(request);
foreach (var document in response.Documents)
{
Console.WriteLine("Output file path: " + document.Path);
}
}
catch (Exception e)
{
Console.WriteLine("Exception while calling api: " + e.Message);
}
}
}
}
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;
using System.Collections.Generic;
using FileInfo = GroupDocs.Merger.Cloud.Sdk.Model.FileInfo;
namespace GroupDocs.Merger.Cloud.Examples.CSharp
{
/// <summary>
/// This example demonstrates how to split the document to several one-page documents (by exact page numbers).
/// </summary>
public class SplitToSinglePages
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new DocumentApi(configuration);
try
{
var fileInfo = new FileInfo
{
FilePath = "WordProcessing/sample-10-pages.docx"
};
var options = new SplitOptions
{
FileInfo = fileInfo,
OutputPath = "Output/split-document",
Pages = new List<int?> { 1, 3 },
Mode = SplitOptions.ModeEnum.Pages
};
var request = new SplitRequest(options);
var response = apiInstance.Split(request);
foreach (var document in response.Documents)
{
Console.WriteLine("Output file path: " + document.Path);
}
}
catch (Exception e)
{
Console.WriteLine("Exception while calling api: " + e.Message);
}
}
}
}
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;
using FileInfo = GroupDocs.Merger.Cloud.Sdk.Model.FileInfo;
namespace GroupDocs.Merger.Cloud.Examples.CSharp
{
/// <summary>
/// This example demonstrates how to split the document to several one-page documents (by start/end page numbers).
/// </summary>
public class SplitToSinglePagesByRange
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new DocumentApi(configuration);
try
{
var fileInfo = new FileInfo
{
FilePath = "WordProcessing/sample-10-pages.docx"
};
var options = new SplitOptions
{
FileInfo = fileInfo,
OutputPath = "Output/split-by-start-end-numbers",
StartPageNumber = 3,
EndPageNumber = 7,
Mode = SplitOptions.ModeEnum.Pages
};
var request = new SplitRequest(options);
var response = apiInstance.Split(request);
foreach (var document in response.Documents)
{
Console.WriteLine("Output file path: " + document.Path);
}
}
catch (Exception e)
{
Console.WriteLine("Exception while calling api: " + e.Message);
}
}
}
}
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;
using FileInfo = GroupDocs.Merger.Cloud.Sdk.Model.FileInfo;
namespace GroupDocs.Merger.Cloud.Examples.CSharp
{
/// <summary>
/// This example demonstrates how to split the document to several one-page documents (by start/end page numbers and even/odd filter).
/// </summary>
public class SplitToSinglePagesByRangeWithFilter
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new DocumentApi(configuration);
try
{
var fileInfo = new FileInfo
{
FilePath = "WordProcessing/sample-10-pages.docx"
};
var options = new SplitOptions
{
FileInfo = fileInfo,
OutputPath = "Output/split-by-start-end-numbers-with-filter",
StartPageNumber = 3,
EndPageNumber = 7,
RangeMode = PageOptions.RangeModeEnum.OddPages,
Mode = SplitOptions.ModeEnum.Pages
};
var request = new SplitRequest(options);
var response = apiInstance.Split(request);
foreach (var document in response.Documents)
{
Console.WriteLine("Output file path: " + document.Path);
}
}
catch (Exception e)
{
Console.WriteLine("Exception while calling api: " + e.Message);
}
}
}
}
using System;
using GroupDocs.Merger.Cloud.Sdk.Api;
using GroupDocs.Merger.Cloud.Sdk.Client;
using GroupDocs.Merger.Cloud.Sdk.Model.Requests;
namespace GroupDocs.Merger.Cloud.Examples.CSharp
{
// Is Storage Exist
class Storage_Exist
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new StorageApi(configuration);
try
{
var request = new StorageExistsRequest(Common.MyStorage);
var response = apiInstance.StorageExists(request);
Console.WriteLine("Expected response type is StorageExist: " + response.Exists.Value.ToString());
}
catch (Exception e)
{
Console.WriteLine("Exception while calling StorageApi: " + e.Message);
}
}
}
}
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;
using System.Collections.Generic;
using FileInfo = GroupDocs.Merger.Cloud.Sdk.Model.FileInfo;
namespace GroupDocs.Merger.Cloud.Examples.CSharp
{
/// <summary>
/// This example demonstrates how to swap document pages.
/// </summary>
public class SwapPages
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new PagesApi(configuration);
try
{
var fileInfo = new FileInfo
{
FilePath = "WordProcessing/four-pages.docx"
};
var options = new SwapOptions
{
FileInfo = fileInfo,
OutputPath = "Output/swap-pages.docx",
FirstPageNumber = 2,
SecondPageNumber = 4
};
var request = new SwapRequest(options);
var response = apiInstance.Swap(request);
Console.WriteLine("Output file path: " + response.Path);
}
catch (Exception e)
{
Console.WriteLine("Exception while calling api: " + e.Message);
}
}
}
}
using GroupDocs.Merger.Cloud.Sdk.Api;
using GroupDocs.Merger.Cloud.Sdk.Client;
using GroupDocs.Merger.Cloud.Sdk.Model.Requests;
using System;
using GroupDocs.Merger.Cloud.Sdk.Model;
using FileInfo = GroupDocs.Merger.Cloud.Sdk.Model.FileInfo;
namespace GroupDocs.Merger.Cloud.Examples.CSharp
{
/// <summary>
/// This example demonstrates how to update document password.
/// </summary>
public class UpdateDocumentPassword
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new SecurityApi(configuration);
try
{
var fileInfo = new FileInfo
{
FilePath = "WordProcessing/password-protected.docx",
Password = "password"
};
var options = new UpdatePasswordOptions
{
FileInfo = fileInfo,
OutputPath = "output/update-password.docx",
NewPassword = "NewPassword"
};
var request = new UpdatePasswordRequest(options);
var response = apiInstance.UpdatePassword(request);
Console.WriteLine("Output file path: " + response.Path);
}
catch (Exception e)
{
Console.WriteLine("Exception while calling api: " + e.Message);
}
}
}
}
using System;
using System.IO;
using GroupDocs.Merger.Cloud.Sdk.Api;
using GroupDocs.Merger.Cloud.Sdk.Client;
using GroupDocs.Merger.Cloud.Sdk.Model.Requests;
namespace GroupDocs.Merger.Cloud.Examples.CSharp
{
// Upload File
class Upload_File
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new FileApi(configuration);
try
{
// Open file in IOStream from local/disc.
var fileStream = File.Open("..\\..\\..\\Data\\WordProcessing\\one-page.docx", FileMode.Open);
var request = new UploadFileRequest("WordProcessing/one-page.docx", fileStream, Common.MyStorage);
var response = apiInstance.UploadFile(request);
Console.WriteLine("Expected response type is FilesUploadResult: " + response.Uploaded.Count.ToString());
}
catch (Exception e)
{
Console.WriteLine("Exception while calling FileApi: " + e.Message);
}
}
}
}
public static void UploadFiles(StorageApi storageApi, FileApi fileApi)
{
var path = @"C:\Files";
var files = Directory.GetFiles(path, "*.pdf", 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 Upload Process Completed.");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment