I have webservice it reads .doc or .docx and send it Base64String by ajax into my plugin this is code of web service
public string ReadDocument(string path)
{
FileStream fsStream = null;
BinaryReader objReader = null;
try
{
////////////////////////
// Now, read binary file
//path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Copy.docx";
fsStream = new FileStream(path, FileMode.Open, FileAccess.Read);
byte[] fileContent = new byte[fsStream.Length];
objReader = new BinaryReader(fsStream);
objReader.Read(fileContent, 0, fileContent.Length);
//toRet.FileContent = fileContent;
//toRet.FileName = "Test.doc";
string StrBase64 = Convert.ToBase64String(fileContent);
string _Document = StrBase64 ;
return _Document;
// FlushResponse(_Document, "application/pdf");
}
catch (Exception ex)
{
// FlushResponse("error");
return "Error " + ex.Message;
}
finally
{
if (objReader != null) objReader.Close();
if (fsStream != null) fsStream.Close();
}
}
I have a problem with body.insertFileFromBase64 when my Base64String comes from .docx it is working but when Base64String comes from .doc it is not working any this is my code in my plugin I send result param it is Base64String comes from ajax
function InsertDocument(result) {
Word.run(function (context) {
// Create a proxy object for the document body.
var body = context.document.body;
body.clear();
// Queue a commmand to insert base64 encoded .docx at the beginning of the content body.
// You will need to implement getBase64() to pass in a string of a base64 encoded docx file.
body.insertFileFromBase64(result, Word.InsertLocation.start);
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
return context.sync().then(function () {
console.log('Added base64 encoded text to the beginning of the document body.');
$("#loading").hide();
});
})
Is any Idea to I can insert .doc to office 2016 by office.js or any other function