I'm trying to get the base64 representation of an active Word document while it's still open in Word and am getting the following error in ReadAllBytes():
The process cannot access the file 'file path' it is being used by another process
public string GetEncodedTemplate()
{
//Convert a Word document's base64 representation
string base64 = String.Empty;
_application.ActiveDocument.Save();
string docPath = _application.ActiveDocument.FullName;
byte[] binarydata = File.ReadAllBytes(docPath);
base64 = System.Convert.ToBase64String(binarydata, 0, binarydata.Length);
return base64;
}
I do understand that the error occurs because the specified document is still open in Word, my question is - Is it still somehow possible to get the base64 representation of the document without resorting to saving to a temp file?
I'm using C# .NET 4.0 And MS Office 2010