Free Support Forum - aspose.cloud

Updating Fields in Microsoft Word document in C# with Aspose.Words REST API is throwing Getting Bad Request

I’ve been trying to use WordsApi.UpdateFields(UpdateFieldsRequest), but I keep getting back a ‘Bad Request’ response.

Blockquote
WordsApi wordsApi = new WordsApi(clientid, secret);
mStream.Position = 0; //reset stream position so it’s not starting at EOF
UpdateFieldsRequest request = new UpdateFieldsRequest(**fileName, **folderName, **storageName, null, null, “NEW^” + **fileName);
DocumentResponse result = wordsApi.UpdateFields(request);

  • fileName is a file that I already have uploaded in my azure storage folder
  • folderName is the file that the original file already resides in
  • storageName is the name I have configured in Aspose Cloud Admin
  • and the last parameter I’m just appending a value on the front of the new file.

This is a C# example. Does anyone have experience using this method?

@bdubose

I am afraid I am unable to reproduce the reported issue at my end. Please share your sample working code here. We will investigate it and will guide you.

WordsApi wordsApi = new WordsApi(ClientId, ClientSecret);
string localFolder = "C:/Temp/";
string localFileName = "test_multi_pages.docx";
string remoteFileName = "TestUpdateDocumentFields.docx";
string destFileName = "TestUpdateDocumentFields_output.docx";
string remoteFolder = "Temp";
string storage = "myGoogleAspose";

Aspose.Words.Cloud.Sdk.Model.Requests.UploadFileRequest uploadRequest = new Aspose.Words.Cloud.Sdk.Model.Requests.UploadFileRequest(System.IO.File.OpenRead(localFolder + localFileName), remoteFolder + "/" + remoteFileName, storageName: storage);
wordsApi.UploadFile(uploadRequest);                       

var request = new UpdateFieldsRequest(
    name: remoteFileName,
    folder: remoteFolder,
    storage: storage,
    destFileName:destFileName
);
var actual = wordsApi.UpdateFields(request);

I’ve been able to get beyond this issue. It was an issue with the storage config in the admin.

That said…I have a scenario where the Word file has fields that are tied to an excel spreadsheet. Does this method work if I have the excel spreadsheet in the same folder already? What I’m expecting is the word file’s fields to match new data from the spreadsheet.

@bdubose

It is good know that you have managed to resolve your issue.

No, UpdateFieldsRequest method does not work in this scenario. I think Mail Merge feature can work in this scenario. However, three types of data sources are supported for the Mail Merge: XML, JSON and CSV. We can convert Excel spreadsheet to CSV using Aspose.Cells Cloud and then use it to populate in Mail Merge Word Template. Hopefully, it will help you to accomplish the task.