I am using compareDocuments function to compare two documents and returning compared document as a byte array as response to front end , I don't know how to convert this byte array and open it as word document on my desktop word after calling my API on taskpane Add-in without downloading the file to my system. I want two show the compared doc on word Desktop.
Below is my C# code for the API which I created: -
[HttpPost]
[Route("compare")]
public async Task<object> compare(string original, string revised)
{
Word.Application wordApp = new Word.Application();
wordApp.Visible = false;
object wordTrue = (object)true;
object wordFalse = (object)false;
object fileToOpen = @original;
object missing = Type.Missing;
Word.Document doc1 = wordApp.Documents.Open(ref fileToOpen,
ref missing, ref wordFalse, ref wordFalse, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref wordTrue, ref missing,
ref missing, ref missing, ref missing);
object fileToOpen1 = @revised;
Word.Document doc2 = wordApp.Documents.Open(ref fileToOpen1,
ref missing, ref wordFalse, ref wordFalse, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing);
Word.Document doc = wordApp.CompareDocuments(doc1, doc2, Word.WdCompareDestination.wdCompareDestinationNew,
Word.WdGranularity.wdGranularityWordLevel,
true, true, true, true, true, true, true, true, true, true, "", true);
doc1.Close(ref missing, ref missing, ref missing);
doc2.Close(ref missing, ref missing, ref missing);
// Hides both original and revised documents
wordApp.ActiveWindow.ShowSourceDocuments = WdShowSourceDocuments.wdShowSourceDocumentsNone;
wordApp.Visible = false;
//doc.Activate();
object filePath = @"C:\Users\yatin\OneDrive\Documents\compared_document.docx";
doc.SaveAs(ref filePath);
doc.Close();
wordApp.Quit();
byte[] byteArray;
using (FileStream fs = new FileStream(filePath.ToString(), FileMode.Open, FileAccess.Read))
{
byteArray = new byte[fs.Length];
fs.Read(byteArray, 0, (int)fs.Length);
}
// Return the byte array to the frontend
return byteArray;
}
I want to use this API with my frontend ADD-IN and show the compared document on the frontend device without downloading it, everytime I run my code the compared document opens up on server side ,so I tried converting the compared doc to byte array and send it as a response to frontend, but I cannot open the word doc on desktop in frontend. Is there any way we can solve this issue?