Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Annotation-CSharp-v2
using System;
using GroupDocs.Annotation.Cloud.Sdk.Api;
using GroupDocs.Annotation.Cloud.Sdk.Client;
using GroupDocs.Annotation.Cloud.Sdk.Model;
using GroupDocs.Annotation.Cloud.Sdk.Model.Requests;
namespace GroupDocs.Annotation.Cloud.Examples.CSharp
{
// Post/Add annotations
class Add_Annotation
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new AnnotateApi(configuration);
try
{
// Set request.
var request = new PostAnnotationsRequest()
{
filePath = "Annotationdocs\\ten-pages.docx",
annotations = new System.Collections.Generic.List<AnnotationInfo>() {
new AnnotationInfo
{
AnnotationPosition = new Point { X = 852, Y = 59.388262910798119 },
Box = new Rectangle { X = 375.89276123046875, Y = 59.388263702392578, Width = 88.7330551147461, Height = 37.7290153503418 },
PageNumber = 0,
PenColor = 1201033,
PenStyle = 0,
PenWidth = 1,
Type = AnnotationInfo.TypeEnum.Area,
CreatorName = "Anonym A."
}
}
};
apiInstance.PostAnnotations(request);
Console.WriteLine("Expected response type is void: Annotation added.");
}
catch (Exception e)
{
Console.WriteLine("Exception while calling Annotation AnnotateApi: " + e.Message);
}
}
}
}
using System.IO;
using System;
using GroupDocs.Annotation.Cloud.Sdk.Client;
using GroupDocs.Annotation.Cloud.Sdk.Api;
namespace GroupDocs.Annotation.Cloud.Examples.CSharp
{
class Common
{
public static string MyAppSid = Common.MyAppSid;
public static string MyAppKey = Common.MyAppKey;
public static string MyStorage = Common.MyStorage;
public static void UploadSampleTestFiles()
{
var storageConfig = new Configuration(MyAppSid, MyAppKey);
StorageApi storageApi = new StorageApi(storageConfig);
FolderApi folderApi = new FolderApi(storageConfig);
FileApi fileApi = new FileApi(storageConfig);
var path = "..\\..\\..\\Data";
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.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.Value)
{
var fileName = Path.GetFileName(file);
var relativeDirPath = relativeFilePath.Replace(fileName, string.Empty).Trim(Path.DirectorySeparatorChar);
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.Annotation.Cloud.Sdk.Api;
using GroupDocs.Annotation.Cloud.Sdk.Client;
using GroupDocs.Annotation.Cloud.Sdk.Model.Requests;
using System;
namespace GroupDocs.Annotation.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("Annotationdocs/one-page1.docx", "Annotationdocs/one-page-copied.docx", Common.MyStorage, Common.MyStorage);
apiInstance.CopyFile(request);
Console.WriteLine("Expected response type is Void: 'Annotationdocs/one-page1.docx' file copied as 'Annotationdocs/one-page-copied.docx'.");
}
catch (Exception e)
{
Console.WriteLine("Exception while calling FileApi: " + e.Message);
}
}
}
}
using System;
using GroupDocs.Annotation.Cloud.Sdk.Api;
using GroupDocs.Annotation.Cloud.Sdk.Client;
using GroupDocs.Annotation.Cloud.Sdk.Model.Requests;
namespace GroupDocs.Annotation.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("Annotationdocs", "Annotationdocs1", Common.MyStorage, Common.MyStorage);
apiInstance.CopyFolder(request);
Console.WriteLine("Expected response type is Void: 'Annotationdocs' folder copied as 'Annotationdocs1'.");
}
catch (Exception e)
{
Console.WriteLine("Exception while calling FolderApi: " + e.Message);
}
}
}
}
using System;
using GroupDocs.Annotation.Cloud.Sdk.Api;
using GroupDocs.Annotation.Cloud.Sdk.Client;
using GroupDocs.Annotation.Cloud.Sdk.Model.Requests;
namespace GroupDocs.Annotation.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: 'Annotationdocs' folder created.");
}
catch (Exception e)
{
Console.WriteLine("Exception while calling FolderApi: " + e.Message);
}
}
}
}
using System;
using GroupDocs.Annotation.Cloud.Sdk.Api;
using GroupDocs.Annotation.Cloud.Sdk.Client;
using GroupDocs.Annotation.Cloud.Sdk.Model;
using GroupDocs.Annotation.Cloud.Sdk.Model.Requests;
namespace GroupDocs.Annotation.Cloud.Examples.CSharp
{
// Delete annotation from document
class Delete_Annotation
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new AnnotateApi(configuration);
try
{
// Set request.
var request = new DeleteAnnotationsRequest()
{
filePath = "Annotationdocs\\one-page.docx"
};
apiInstance.DeleteAnnotations(request);
Console.WriteLine("Expected response type is Void: Annotation deleted from document.");
}
catch (Exception e)
{
Console.WriteLine("Exception while calling Annotation AnnotateApi: " + e.Message);
}
}
}
}
using GroupDocs.Annotation.Cloud.Sdk.Api;
using GroupDocs.Annotation.Cloud.Sdk.Client;
using GroupDocs.Annotation.Cloud.Sdk.Model.Requests;
using System;
namespace GroupDocs.Annotation.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("Annotationdocs1/one-page1.docx", Common.MyStorage);
apiInstance.DeleteFile(request);
Console.WriteLine("Expected response type is Void: 'Annotationdocs1/one-page1.docx' deleted.");
}
catch (Exception e)
{
Console.WriteLine("Exception while calling FileApi: " + e.Message);
}
}
}
}
using System;
using GroupDocs.Annotation.Cloud.Sdk.Api;
using GroupDocs.Annotation.Cloud.Sdk.Client;
using GroupDocs.Annotation.Cloud.Sdk.Model.Requests;
namespace GroupDocs.Annotation.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("Annotationdocs/Annotationdocs1", Common.MyStorage, true);
apiInstance.DeleteFolder(request);
Console.WriteLine("Expected response type is Void: 'Annotationdocs/Annotationdocs1' folder deleted recusrsively.");
}
catch (Exception e)
{
Console.WriteLine("Exception while calling FolderApi: " + e.Message);
}
}
}
}
using System;
using GroupDocs.Annotation.Cloud.Sdk.Api;
using GroupDocs.Annotation.Cloud.Sdk.Client;
using GroupDocs.Annotation.Cloud.Sdk.Model;
using GroupDocs.Annotation.Cloud.Sdk.Model.Requests;
namespace GroupDocs.Annotation.Cloud.Examples.CSharp
{
// Delete document pages created as images from File
class Delete_Pages
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new PreviewApi(configuration);
try
{
// Set request.
var request = new DeletePagesRequest()
{
filePath = "Annotationdocs\\one-page.docx"
};
apiInstance.DeletePages(request);
Console.WriteLine("Expected response type is Void: pages deleted.");
}
catch (Exception e)
{
Console.WriteLine("Exception while calling Annotation PreviewApi: " + e.Message);
}
}
}
}
using System;
using GroupDocs.Annotation.Cloud.Sdk.Api;
using GroupDocs.Annotation.Cloud.Sdk.Client;
using GroupDocs.Annotation.Cloud.Sdk.Model;
using GroupDocs.Annotation.Cloud.Sdk.Model.Requests;
namespace GroupDocs.Annotation.Cloud.Examples.CSharp
{
// Get document information from File
class DocumentInfo_File
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new InfoApi(configuration);
try
{
// Set request.
var request = new GetInfoRequest()
{
filePath = "Annotationdocs\\one-page.docx",
password = null
};
var response = apiInstance.GetInfo(request);
Console.WriteLine("Expected response type is InfoResult: " + response.ToString());
}
catch (Exception e)
{
Console.WriteLine("Exception while calling Annotation InfoApi: " + e.Message);
}
}
}
}
using GroupDocs.Annotation.Cloud.Sdk.Api;
using GroupDocs.Annotation.Cloud.Sdk.Client;
using GroupDocs.Annotation.Cloud.Sdk.Model.Requests;
using System;
namespace GroupDocs.Annotation.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("Annotationdocs/one-page.docx", Common.MyStorage);
var response = apiInstance.DownloadFile(request);
Console.WriteLine("Expected response type is Stream: " + response.Length.ToString());
}
catch (Exception e)
{
Console.WriteLine("Exception while calling FileApi: " + e.Message);
}
}
}
}
using System;
using GroupDocs.Annotation.Cloud.Sdk.Api;
using GroupDocs.Annotation.Cloud.Sdk.Client;
using GroupDocs.Annotation.Cloud.Sdk.Model;
using GroupDocs.Annotation.Cloud.Sdk.Model.Requests;
namespace GroupDocs.Annotation.Cloud.Examples.CSharp
{
// Get document annotation from File
class Get_Annotation
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new AnnotateApi(configuration);
try
{
// Set request.
var request = new GetImportRequest()
{
filePath = "Annotationdocs\\ten-pages.docx"
};
var response = apiInstance.GetImport(request);
Console.WriteLine("Expected response type is List<AnnotationInfo>: " + response.ToString());
}
catch (Exception e)
{
Console.WriteLine("Exception while calling Annotation AnnotateApi: " + e.Message);
}
}
}
}
using System;
using GroupDocs.Annotation.Cloud.Sdk.Api;
using GroupDocs.Annotation.Cloud.Sdk.Client;
using GroupDocs.Annotation.Cloud.Sdk.Model.Requests;
namespace GroupDocs.Annotation.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.Annotation.Cloud.Sdk.Api;
using GroupDocs.Annotation.Cloud.Sdk.Client;
using GroupDocs.Annotation.Cloud.Sdk.Model;
using GroupDocs.Annotation.Cloud.Sdk.Model.Requests;
namespace GroupDocs.Annotation.Cloud.Examples.CSharp
{
// Get document with annotation result as Stream
class Get_Export_Document
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new AnnotateApi(configuration);
try
{
// Set request.
var request = new GetExportRequest()
{
filePath = "Annotationdocs\\ten-pages.docx",
password = null,
annotatedPages = true,
annotationTypes = null,
firstPage = 1,
lastPage = 2
};
var response = apiInstance.GetExport(request);
Console.WriteLine("Expected response type is Stream: Document Length: " + response.Length.ToString());
}
catch (Exception e)
{
Console.WriteLine("Exception while calling Annotation AnnotateApi: " + e.Message);
}
}
}
}
using System;
using GroupDocs.Annotation.Cloud.Sdk.Api;
using GroupDocs.Annotation.Cloud.Sdk.Client;
using GroupDocs.Annotation.Cloud.Sdk.Model.Requests;
namespace GroupDocs.Annotation.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.Annotation.Cloud.Sdk.Api;
using GroupDocs.Annotation.Cloud.Sdk.Client;
using GroupDocs.Annotation.Cloud.Sdk.Model.Requests;
namespace GroupDocs.Annotation.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("Annotationdocs", 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 System;
using GroupDocs.Annotation.Cloud.Sdk.Api;
using GroupDocs.Annotation.Cloud.Sdk.Client;
using GroupDocs.Annotation.Cloud.Sdk.Model;
using GroupDocs.Annotation.Cloud.Sdk.Model.Requests;
namespace GroupDocs.Annotation.Cloud.Examples.CSharp
{
// Get document pages as images from File
class Get_Pages
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new PreviewApi(configuration);
try
{
// Set request.
var request = new GetPagesRequest()
{
filePath = "Annotationdocs\\ten-pages.docx",
password = null,
pageNumber = 1,
countPagesToConvert = 1,
enableCaching = false,
cacheStoragePath = null,
withoutAnnotations = true
};
var response = apiInstance.GetPages(request);
Console.WriteLine("Expected response type is PageImages: " + response.ToString());
}
catch (Exception e)
{
Console.WriteLine("Exception while calling Annotation PreviewApi: " + e.Message);
}
}
}
}
using System;
using GroupDocs.Annotation.Cloud.Sdk.Api;
using GroupDocs.Annotation.Cloud.Sdk.Client;
using GroupDocs.Annotation.Cloud.Sdk.Model;
using GroupDocs.Annotation.Cloud.Sdk.Model.Requests;
namespace GroupDocs.Annotation.Cloud.Examples.CSharp
{
// Get document as PDF with annotation result as Stream
class Get_PDF
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new AnnotateApi(configuration);
try
{
// Set request.
var request = new GetPdfRequest()
{
filePath = "Annotationdocs\\ten-pages.docx"
};
var response = apiInstance.GetPdf(request);
Console.WriteLine("Expected response type is Stream: Document Length: " + response.Length.ToString());
}
catch (Exception e)
{
Console.WriteLine("Exception while calling Annotation AnnotateApi: " + e.Message);
}
}
}
}
using System;
using GroupDocs.Annotation.Cloud.Sdk.Api;
using GroupDocs.Annotation.Cloud.Sdk.Client;
namespace GroupDocs.Annotation.Cloud.Examples.CSharp
{
// Get All Supported Formats
class Get_All_Supported_Formats
{
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(string.Format("{0}: {1}", entry.FileFormat, string.Join(",", entry.Extension)));
}
}
catch (Exception e)
{
Console.WriteLine("Exception while calling Annotation InfoApi: " + e.Message);
}
}
}
}
using GroupDocs.Annotation.Cloud.Sdk.Api;
using GroupDocs.Annotation.Cloud.Sdk.Client;
using GroupDocs.Annotation.Cloud.Sdk.Model.Requests;
using System;
namespace GroupDocs.Annotation.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("Annotationdocs/one-page1.docx", "Annotationdocs1/one-page1.docx", Common.MyStorage, Common.MyStorage);
apiInstance.MoveFile(request);
Console.WriteLine("Expected response type is Void: 'Annotationdocs/one-page1.docx' file moved to 'Annotationdocs1/one-page1.docx'.");
}
catch (Exception e)
{
Console.WriteLine("Exception while calling FileApi: " + e.Message);
}
}
}
}
using GroupDocs.Annotation.Cloud.Sdk.Api;
using GroupDocs.Annotation.Cloud.Sdk.Client;
using GroupDocs.Annotation.Cloud.Sdk.Model.Requests;
using System;
namespace GroupDocs.Annotation.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("Annotationdocs1", "Annotationdocs\\Annotationdocs1", Common.MyStorage, Common.MyStorage);
apiInstance.MoveFolder(request);
Console.WriteLine("Expected response type is Void: 'Annotationdocs1' folder moved to 'Annotationdocs/Annotationdocs1'.");
}
catch (Exception e)
{
Console.WriteLine("Exception while calling FolderApi: " + e.Message);
}
}
}
}
using System;
using GroupDocs.Annotation.Cloud.Sdk.Api;
using GroupDocs.Annotation.Cloud.Sdk.Client;
using GroupDocs.Annotation.Cloud.Sdk.Model.Requests;
namespace GroupDocs.Annotation.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("Annotationdocs/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 System;
using GroupDocs.Annotation.Cloud.Sdk.Api;
using GroupDocs.Annotation.Cloud.Sdk.Client;
using GroupDocs.Annotation.Cloud.Sdk.Model.Requests;
namespace GroupDocs.Annotation.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 System;
using System.IO;
using GroupDocs.Annotation.Cloud.Sdk.Api;
using GroupDocs.Annotation.Cloud.Sdk.Client;
using GroupDocs.Annotation.Cloud.Sdk.Model.Requests;
namespace GroupDocs.Annotation.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\\Annotationdocs\\one-page.docx", FileMode.Open);
var request = new UploadFileRequest("Annotationdocs/one-page1.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);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.