|
1 | 1 | # GroupDocs.Conversion Cloud SDK for .NET |
2 | 2 |
|
3 | | -This repository contains GroupDocs.Conversion Cloud SDK for .NET source code. This SDK allows you to work with GroupDocs.Conversion Cloud REST APIs in your .NET applications. |
| 3 | +This repository contains GroupDocs.Conversion Cloud SDK for .NET source code. This SDK has been developed to help you get started with using our document conversion REST API, allowing to seamlessly convert your documents to any format you need. With this single API, you can convert back and forth between over 50 types of documents and images, including all Microsoft Office and OpenDocument file formats, PDF documents, HTML, CAD, raster images and many more. |
4 | 4 |
|
5 | 5 | ## How to use the SDK |
6 | 6 |
|
7 | 7 | The complete source code is available in this repository folder, you can either directly use it in your project via NuGet package manager. For more details, please visit our [documentation website](https://docs.groupdocs.cloud/display/conversioncloud/Available+SDKs#AvailableSDKs-.NET). |
8 | 8 |
|
9 | | -## Dependencies |
| 9 | +### Create an account |
| 10 | +Creating an account is very simple. Go to Dashboard to create a free account. |
| 11 | +We’re using Single Sign On across our websites, therefore, if you already have an account with our services, you can use it to also access the [Dashboard](https://dashboard.groupdocs.cloud). |
10 | 12 |
|
11 | | -- [Json.NET](https://www.nuget.org/packages/Newtonsoft.Json) |
| 13 | +### Create an API client app |
| 14 | +Before you can make any requests to GroupDocs Cloud API you need to get a Client Id and a Client Secret. This will be used to invoke GroupDocs Cloud API. You can get it by creating a new [Application](https://dashboard.groupdocs.cloud/applications). |
12 | 15 |
|
13 | | -## Getting Started |
| 16 | +## Convert document |
14 | 17 |
|
15 | 18 | ```csharp |
16 | | -using System; |
17 | | -using System.Diagnostics; |
18 | 19 | using GroupDocs.Conversion.Cloud.Sdk.Api; |
| 20 | +using GroupDocs.Conversion.Cloud.Sdk.Client; |
| 21 | +using GroupDocs.Conversion.Cloud.Sdk.Model.Requests; |
19 | 22 |
|
20 | | -namespace Example |
| 23 | +namespace ConversionCloudExample |
21 | 24 | { |
22 | | - public class Example |
| 25 | + internal class Program |
23 | 26 | { |
24 | | - public void Main() |
| 27 | + static void Main(string[] args) |
25 | 28 | { |
26 | | - //TODO: Get your AppSID and AppKey at https://dashboard.groupdocs.cloud (free registration is required). |
27 | | - var appSid = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"; |
28 | | - var appKey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; |
| 29 | + // For complete examples and data files, please go to https://github.com/groupdocs-conversion-cloud/groupdocs-conversion-cloud-dotnet-samples |
| 30 | + string MyClientSecret = ""; // Get ClientId and ClientSecret from https://dashboard.groupdocs.cloud |
| 31 | + string MyClientId = ""; // Get ClientId and ClientSecret from https://dashboard.groupdocs.cloud |
29 | 32 |
|
30 | | - var api = new InfoApi(appSid, appKey); |
| 33 | + var configuration = new Configuration(MyClientId, MyClientSecret); |
31 | 34 |
|
32 | | - try |
33 | | - { |
34 | | - // Get supported file formats |
35 | | - var formats = api.GetSupportedConversionTypes(new GetSupportedConversionTypesRequest()); |
36 | | - |
37 | | - foreach (var format in formats) |
38 | | - { |
39 | | - Debug.Print(format.SourceFormat); |
40 | | - } |
41 | | - } |
42 | | - catch (Exception e) |
| 35 | + // Create necessary API instances |
| 36 | + var apiInstance = new ConvertApi(configuration); |
| 37 | + |
| 38 | + // Prepare request |
| 39 | + var fileStream = File.Open("myFile.docx", FileMode.Open); |
| 40 | + var request = new ConvertDocumentDirectRequest("pdf", fileStream); |
| 41 | + |
| 42 | + // Convert to specified format |
| 43 | + var response = apiInstance.ConvertDocumentDirect(request); |
| 44 | + Console.WriteLine("Document converted successfully: " + response.Length); |
| 45 | + } |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +``` |
| 50 | + |
| 51 | +## Convert document using cloud storage |
| 52 | + |
| 53 | +```csharp |
| 54 | +using GroupDocs.Conversion.Cloud.Sdk.Api; |
| 55 | +using GroupDocs.Conversion.Cloud.Sdk.Client; |
| 56 | +using GroupDocs.Conversion.Cloud.Sdk.Model; |
| 57 | +using GroupDocs.Conversion.Cloud.Sdk.Model.Requests; |
| 58 | + |
| 59 | +namespace ConversionCloudExample |
| 60 | +{ |
| 61 | + internal class Program |
| 62 | + { |
| 63 | + static void Main(string[] args) |
| 64 | + { |
| 65 | + // For complete examples and data files, please go to https://github.com/groupdocs-conversion-cloud/groupdocs-conversion-cloud-dotnet-samples |
| 66 | + string MyClientSecret = ""; // Get ClientId and ClientSecret from https://dashboard.groupdocs.cloud |
| 67 | + string MyClientId = ""; // Get ClientId and ClientSecret from https://dashboard.groupdocs.cloud |
| 68 | +
|
| 69 | + var configuration = new Configuration(MyClientId, MyClientSecret); |
| 70 | + |
| 71 | + // Create necessary API instances |
| 72 | + var fileApi = new FileApi(configuration); |
| 73 | + var convertApi = new ConvertApi(configuration); |
| 74 | + |
| 75 | + // Upload file to cloud storage |
| 76 | + var fileStream = File.Open("myFile.docx", FileMode.Open); |
| 77 | + fileApi.UploadFile(new UploadFileRequest("myFile.docx", fileStream)); |
| 78 | + |
| 79 | + // Prepare convert settings |
| 80 | + var settings = new ConvertSettings |
43 | 81 | { |
44 | | - Debug.Print("Something went wrong: " + e.Message); |
45 | | - } |
| 82 | + FilePath = "myFile.docx", |
| 83 | + Format = "pdf", |
| 84 | + OutputPath = "converted" |
| 85 | + }; |
| 86 | + |
| 87 | + // Convert to specified format |
| 88 | + convertApi.ConvertDocument(new ConvertDocumentRequest(settings)); |
| 89 | + |
| 90 | + // Download the result |
| 91 | +
|
| 92 | + var response = fileApi.DownloadFile(new DownloadFileRequest("converted/myFile.pdf")); |
| 93 | + Console.WriteLine("Expected response type is Stream: " + response.Length.ToString()); |
46 | 94 | } |
47 | 95 | } |
48 | 96 | } |
|
0 commit comments