public static void Run()
        {
            // ExStart:1
            WordsApi   wordsApi   = new WordsApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH);
            StorageApi storageApi = new StorageApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH);

            String fileName = "SampleWordDocument.docx";
            String storage  = "dropboxstorage";
            String folder   = null;

            ReplaceTextRequest body = new ReplaceTextRequest();

            body.OldValue = "aspose";
            body.NewValue = "aspose.com";

            try
            {
                // Upload the file
                storageApi.PutCreate(fileName, "", storage, System.IO.File.ReadAllBytes(Common.GetDataDir() + fileName));
                // Invoke Aspose.Words Cloud SDK API to replace text in a document using third party storage
                Com.Aspose.Words.Model.ReplaceTextResponse apiResponse = wordsApi.PostReplaceText(fileName, fileName, storage, folder, body);

                if (apiResponse != null && apiResponse.Status.Equals("OK"))
                {
                    Console.WriteLine("Text replaced successfully");
                    Console.ReadKey();
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace);
            }
            // ExEnd:1
        }
        public void TestReplaceText()
        {
            string remoteFileName = "TestReplaceText.docx";
            string localFile      = "Common/test_multi_pages.docx";

            this.UploadFileToStorage(
                remoteDataFolder + "/" + remoteFileName,
                null,
                null,
                File.ReadAllBytes(LocalTestDataFolder + localFile)
                );

            var request = new ReplaceTextRequest(
                name: remoteFileName,
                replaceText: new ReplaceTextParameters()
            {
                OldValue = "Testing",
                NewValue = "Aspose testing"
            },
                folder: remoteDataFolder,
                destFileName: BaseTestOutPath + "/" + remoteFileName
                );
            var actual = this.WordsApi.ReplaceText(request);

            Assert.AreEqual(3, actual.Matches);
        }
Ejemplo n.º 3
0
        public void TestPostReplaceText()
        {
            var localName    = "test_multi_pages.docx";
            var remoteName   = "TestPostReplaceText.docx";
            var fullName     = Path.Combine(this.dataFolder, remoteName);
            var destFileName = Path.Combine(BaseTestOutPath, remoteName);
            var body         = new ReplaceTextRequest {
                OldValue = "aspose", NewValue = "aspose new"
            };

            this.StorageApi.PutCreate(fullName, null, null, File.ReadAllBytes(BaseTestContext.GetDataDir(BaseTestContext.CommonFolder) + localName));

            var request = new PostReplaceTextRequest(remoteName, body, this.dataFolder, destFileName: destFileName);
            var actual  = this.WordsApi.PostReplaceText(request);

            Assert.AreEqual(200, actual.Code);
        }