Free Support Forum - aspose.cloud

Aspose.Words.Cloud.Sdk


#1

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


#2

@ron.macinnis

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/Examples/CompareDocuments/compare_document.py

Please let us know if it does serve your purpose.

P.S. All Aspose.Words Cloud SDKs are available here: https://github.com/aspose-words-cloud/


#3

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.


#4

@ron.macinnis

.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!


#5

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

  1. Where shall I find the output file .
  2. What is the use of BaseProductUri . When it is not used any where in the code.
    Regards
    Ron

#6

@ron.macinnis

Where shall I find the output file.

Since we have specified the value of destFileName parameter, the API will save CompareDocumentOut.doc document at https://dashboard.aspose.cloud/#/files.

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.


#7

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


#9

@ron.macinnis

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!


#10

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


#11

@ron.macinnis

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.