Hi Support Team
Can you please direct me to a code for compare of documents.
I am facing the problem is that URL of the server where I have to upload the bytes of the document.
Regards
Ron
You have not mentioned the programming language, otherwise, we would share the relevant code in that particular language. You will use POST /words/{name}/compareDocument API to compare two documents.
You can find Compare Documents API example in Python here https://github.com/aspose-words-cloud/aspose-words-cloud-python/blob/master/test/api/document/test_compare_document.py
Please let us know if it does serve your purpose.
P.S. All Aspose.Words Cloud SDKs are available here: Aspose.Words Cloud · GitHub
We are using the .NET SDK for Aspose.Words Cloud. Our programming language is C#. We’re using the .NET SDK sample code from the downloaded sample project from GitHub for the SDK.
We are not sure what folder(s) we are supposed to indicate when we upload the bytes of our two documents we wanting to compare to the remote server.
.NET example of Compare Documents API is given below:
class Program
{
protected const string BaseProductUri = @"https://api.aspose.cloud";
protected const string MyAppKey = "";
protected const string MyAppSid = "";
static void Main(string[] args)
{
WordsApi WordsApi = new WordsApi(MyAppKey, MyAppSid);
StorageApi StorageApi = new StorageApi(MyAppKey, MyAppSid);
var firstDocument = "compareTestDoc1.doc";
var secondDocument = "compareTestDoc2.doc";
var destFileName = "CompareDocumentOut.doc";
var compareData = new CompareData { Author = "author", ComparingWithDocument = secondDocument, DateTime = new DateTime(2018, 12, 30) };
// Upload firstDocument to Cloud Storage
PutCreateRequest request = new PutCreateRequest(firstDocument, File.OpenRead(@"c:\Data\" + firstDocument), null, null);
StorageApi.PutCreate(request);
// Upload secondDocument to Cloud Storage
request = new PutCreateRequest(secondDocument, File.OpenRead(@"c:\Data\" + secondDocument), null, null);
StorageApi.PutCreate(request);
var compareDocumentRequest = new PostCompareDocumentRequest(firstDocument, compareData, null, destFileName: destFileName);
var apiResponse = WordsApi.PostCompareDocument(compareDocumentRequest);
}
}
Moreover, your project NuGet packages window should look as follows:
We hope this helps!
Hi sohail
I have excatly copied the code in web application asp.net C#. I have even checked the NuGet packages everything looks accordingly how you have described .I have executed the code it did not give me any error. But niether it gave me output file.
My queries are
- Where shall I find the output file .
- What is the use of BaseProductUri . When it is not used any where in the code.
Regards
Ron
Where shall I find the output file.
Since we have specified the value of destFileName
parameter, the API will save CompareDocumentOut.doc
document at Dashboard.
If you do not specify the value of destFileName
parameter, the API will return the output document in the response.
I believe you know that before calling the above code, you need to specify the value of MyAppKey
and MyAppSid
variables. This article explains how you can get your App Key and App SID.
What is the use of BaseProductUri . When it is not used any where in the code.
In the above code, there is no need for BaseProductUri
, you may delete it.
Please feel free to contact us if you need any further information.
Hi Sohail
Thanks for your inputs to all my queries.
We are going ahead with the second option that is the API will return the output document in the response.
When apiResponse.Document it returns me aspose.words.cloud.sdk.model.Document. I wanted to save this document. But I am not getting any option to save that document.
Regards
Ron
The following code will save the output document CompareDocumentOut.doc to your local storage:
class Program
{
protected const string MyAppKey = "";
protected const string MyAppSid = "";
static void Main(string[] args)
{
WordsApi WordsApi = new WordsApi(MyAppKey, MyAppSid);
StorageApi StorageApi = new StorageApi(MyAppKey, MyAppSid);
var firstDocument = "compareTestDoc1.doc";
var secondDocument = "compareTestDoc2.doc";
var destFileName = "CompareDocumentOut.doc";
var compareData = new CompareData { Author = "author", ComparingWithDocument = secondDocument, DateTime = new DateTime(2018, 12, 30) };
// Upload firstDocument to Cloud Storage
PutCreateRequest request = new PutCreateRequest(firstDocument, File.OpenRead(@"c:\Data\" + firstDocument), null, null);
StorageApi.PutCreate(request);
// Upload secondDocument to Cloud Storage
request = new PutCreateRequest(secondDocument, File.OpenRead(@"c:\Data\" + secondDocument), null, null);
StorageApi.PutCreate(request);
var compareDocumentRequest = new PostCompareDocumentRequest(firstDocument, compareData, null, destFileName: destFileName);
var apiResponse = WordsApi.PostCompareDocument(compareDocumentRequest);
// Download File from Cloud Storage
GetDownloadRequest downloadRequest = new GetDownloadRequest();
downloadRequest.Path = destFileName;
var responseStream = StorageApi.GetDownload(downloadRequest);
// Save the file to disk
var fileStream = File.Create(@"c:\Data\" + destFileName);
responseStream.Seek(0, SeekOrigin.Begin);
responseStream.CopyTo(fileStream);
fileStream.Close();
}
}
We hope this helps!
Hi Sohail
I am really thankful to you. Things worked very well and document got saved to my local machine.
Can you please direct me to documentation or source code where I can get help for various points. I have this one query , Is there a way to prevent it from comparing formatting changes?
If you have done this code all by your self can you please guide me with code that prevent comparing formatting.
Regards
Ron
Unfortunately, at present, we do not support compare options. However, Our Native APIs are providing this feature. I have logged the request in our internal tracking software (WORDSCLOUD-671) for the implementation of Compare Options in Aspose REST APIs. We will update you here as soon as the implementation is complete.
Thanks for your patience. Please note, we have implemented your above feature request in Aspose.Words Cloud 20.4. We have introduced CompareOptions in the new release. Hopefully it will help you to accomplish your task. Please feel free to contact us for any further assistance.