const string appSID = "XXXXXXXXXXXXXXXX"; // apply user's appSID const string appKey = "XXXXXXXXXXXXXXXX"; // apply user's key const string SERVICE_API_BASE_URL = "https://api.aspose.cloud/v1.1/html"; const string htmlDocName = "testpage1.html"; const string storageFolderName = "MyFolder"; public static void Main(string[] args) { UploadDocument(htmlDocName, storageFolderName); ApiRun(htmlDocName, storageFolderName, "en", "de"); ApiRun(htmlDocName, storageFolderName, "en", "fr"); ApiRun(htmlDocName, storageFolderName, "en", "ru"); } private static void UploadDocument(string fileName, string folder) { var url = $"{SERVICE_API_BASE_URL}/storage/file/{folder}/{fileName}"; // calculate the signature based on the URL with appSID and appKey var sign = CalcUrlSignature(url, appKey); var signedUrl = $"{url}&signature={sign}"; Stream docstream = new MemoryStream(); using (StreamWriter sw = new StreamWriter(docstream)) { sw.Write("<p>" + "This is the first text paragraph. There is some more text." + "</p>" + "<p>" + "<div>There is a translation example you could try. It translates text from English to German, French and Russian simultaneously.</div>" + "<div>Here's a working example you can run in a console application. What do you think about it?</div>" + "</p>" + "<div>Who is the president of the United States?</div>" + "<p>This is the second paragraph.</p>" + "<p>" + "Here is the last paragraph. Much more text could be here." + "</p>"); } StreamContent streamContent = new StreamContent(docstream); streamContent.Headers.ContentType = new MediaTypeHeaderValue("text/html"); var client = new HttpClient(); // check if the document already exists is skipped for shortness var response = client.PutAsync(signedUrl, streamContent); } private static ApiRun(string name, string folder, string fromLang, string toLang) { var url = $"{SERVICE_API_BASE_URL}/{name}/translate/{fromLang}/{toLang}?folder={folder}&appSid={appSID}"; // calculate the signature based on the URL with appSID and appKey var sign = CalcUrlSignature(url, appKey); var signedUrl = $"{url}&signature={sign}"; var response = client.GetAsync(url).Result; // REST API call - GET if (response.HttpStatus == HttpStatusCode.OK) { var contentType = response.Content.Headers.ContentType; Stream content = response.Content.ReadAsStreamAsync().Result; // check the type of response content if (contentType.Equals(new MediaTypeHeaderValue("text/html"))) { // if response type is HTML, process stream as HTML layout using (StreamReader rdr = new StreamReader(content)) { Console.Write(rdr.ReadToEnd()); } } else if (contentType.Equals(new MediaTypeHeaderValue("application/zip"))) { // if response type is ZIP, unpack the archive stream // to get HTML page with the resource files } } } private static string CalcUrlSignature(string url, string appKey) { // calculate URL signature here - skipped for shorteness }