Converting current word document to base64 RRS feed

  • Question

  • Hi,

    I would like to know how to convert an active word document to base64 format using c#.

    Saturday, September 14, 2013 9:01 AM


  • Hello,

    Because Word has a lock on an active document. In order to get the current document bytes you would need to copy the existing file (File.Copy) or save to a new file (Document.SaveAs or IPersistFile.Save) for reading its content.

    Try to use the following code to get the base64 representation of an active Word document while it's still open in Word:

    public string GetEncodedTemplate()
                //Convert a Word document's base64 representation
                string base64 = String.Empty;
                string docPath = _application.ActiveDocument.FullName;
                byte[] binarydata = File.ReadAllBytes(docPath);
                base64 = System.Convert.ToBase64String(binarydata, 0, binarydata.Length);
                return base64;

    Check these:

    Best Regards,
    A Beginner :)
    Please remember to mark the replies as answers if they help

    Monday, September 16, 2013 8:19 AM