public void TestOpenSaveTextWithOptions()
        {
            // Load
            var testFile    = TestFiles.Txt;
            var loadOptions = new TextLoadOptions
            {
                FileInfo         = testFile.ToFileInfo(),
                OutputPath       = DefaultOutputPath,
                EnablePagination = true,
                LeadingSpaces    = TextLoadOptions.LeadingSpacesEnum.Trim,
                RecognizeLists   = true
            };

            var loadResult = EditApi.Load(new LoadRequest(loadOptions));

            Assert.IsNotEmpty(loadResult.HtmlPath);
            Assert.IsNotEmpty(loadResult.ResourcesPath);

            // Save
            var saveOptions = new TextSaveOptions
            {
                FileInfo            = testFile.ToFileInfo(),
                HtmlPath            = loadResult.HtmlPath,
                ResourcesPath       = loadResult.ResourcesPath,
                OutputPath          = $"{DefaultOutputPath}/{testFile.FileName}",
                AddBidiMarks        = true,
                Encoding            = "UTF-8",
                Format              = "txt",
                PreserveTableLayout = true
            };

            var saveResult = EditApi.Save(new SaveRequest(saveOptions));

            Assert.AreEqual(saveOptions.OutputPath, saveResult.Path);
        }
        public static void Run()
        {
            try
            {
                // Create necessary API instances
                var editApi = new EditApi(Common.GetConfig());
                var fileApi = new FileApi(Common.GetConfig());

                // The document already uploaded into the storage.
                // Load it into editable state
                var loadOptions = new TextLoadOptions
                {
                    FileInfo = new FileInfo
                    {
                        FilePath = "Text/document.txt"
                    },
                    OutputPath = "output"
                };

                var loadResult = editApi.Load(new LoadRequest(loadOptions));

                // Download html document
                var stream     = fileApi.DownloadFile(new DownloadFileRequest(loadResult.HtmlPath));
                var htmlString = new StreamReader(stream, Encoding.UTF8).ReadToEnd();

                // Edit something...
                htmlString = htmlString.Replace("Page Text", "New Text");

                // Upload html back to storage
                fileApi.UploadFile(new UploadFileRequest(loadResult.HtmlPath,
                                                         new MemoryStream(Encoding.UTF8.GetBytes(htmlString))));

                // Save html back to txt
                var saveOptions = new TextSaveOptions
                {
                    FileInfo      = loadOptions.FileInfo,
                    OutputPath    = "output/edited.txt",
                    HtmlPath      = loadResult.HtmlPath,
                    ResourcesPath = loadResult.ResourcesPath
                };

                var saveResult = editApi.Save(new SaveRequest(saveOptions));

                // Done.
                Console.WriteLine("Document edited: " + saveResult.Path);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: " + e.Message);
            }
        }
        private ISaveOptions GetSaveOptions(string guid)
        {
            string       extension = Path.GetExtension(guid).Replace(".", "").ToLowerInvariant();
            ISaveOptions options   = null;

            if (extension.ToLowerInvariant().Equals("txt"))
            {
                options = new TextSaveOptions();
            }
            else
            {
                foreach (var item in typeof(WordProcessingFormats).GetFields())
                {
                    if (item.Name.ToLowerInvariant().Equals("auto"))
                    {
                        continue;
                    }
                    if (item.Name.ToLowerInvariant().Equals(extension))
                    {
                        WordProcessingFormats format = WordProcessingFormats.FromExtension(extension);
                        options = new WordProcessingSaveOptions(format);
                        break;
                    }
                }

                foreach (var item in typeof(PresentationFormats).GetFields())
                {
                    if (item.Name.ToLowerInvariant().Equals("auto"))
                    {
                        continue;
                    }

                    if (item.Name.ToLowerInvariant().Equals(extension))
                    {
                        PresentationFormats format = PresentationFormats.FromExtension(extension);
                        options = new PresentationSaveOptions(format);
                        break;
                    }
                }

                if (options == null)
                {
                    SpreadsheetFormats format = SpreadsheetFormats.FromExtension(extension);
                    options = new SpreadsheetSaveOptions(format);
                }
            }

            return(options);
        }