I am trying to get a base64 view of an active Word document while it is still open in Word and I get the following error in ReadAllBytes ():
The process cannot access the file "file path" used by another process
public string GetEncodedTemplate()
{
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 understand that the error occurs because the specified document is still open in Word, my question is: is it still possible to get a base64 representation of the document without resorting to saving a temporary file?
I am using C # .NET 4.0 AND MS Office 2010
source
share