/// <summary> /// Convert document from request content to format specified. /// </summary> /// <param name="format">The destination format.</param> /// <param name="outPath">Path to save result. Must be a cloud storage path (MyFolder\out.doc).</param> /// <param name="inputFilePath">Input file e.g. c:\input.doc).</param> public void ConvertDocument(WordOutputFormat format, string outPath, string inputFilePath) { // PUT words/convert?appSid={appSid}&format={format}&outPath={outPath} string apiUrl = string.Format(@"words/convert?format={0}&outPath={1}", format, outPath); ServiceController.Put(apiUrl, AppSid, AppKey, File.ReadAllBytes(inputFilePath)); }
/// <summary> /// Convert document to format specified. /// </summary> /// <param name="name">The file name.</param> /// <param name="format">The destination format.</param> /// <param name="folder">The document folder.</param> /// <param name="outPath">Path to save result. It can be local (e.g. c:\out.doc) or cloud storage path (MyFolder\out.doc).</param> /// <param name="storage">The document storage.</param> public void ConvertDocument(string name, WordOutputFormat format, string folder, string outPath, string storage = "") { // GET words/{name}?appSid={appSid}&format={format}&storage={storage}&folder={folder}&outPath={outPath} string apiUrl = string.Format(@"words/{0}?format={1}&storage={2}&folder={3}&outPath={4}", name, format, storage, folder, (outPath.Contains(@":\") ? string.Empty : outPath)); if (!string.IsNullOrEmpty(outPath) && Directory.Exists(Path.GetDirectoryName(outPath))) { using (Stream responseStream = ServiceController.GetStream(apiUrl, AppSid, AppKey)) using (Stream file = File.OpenWrite(outPath)) { ServiceController.CopyStream(responseStream, file); } } else { ServiceController.Get(apiUrl, AppSid, AppKey); } }