VSTO实现读取WORD字节流

通过先保存文件,再读磁盘方式。此处非另存为,也不需要改变WORD中现有文件的路径。

var document = Globals.ThisAddIn.Application.ActiveDocument;
            var ipersistfile = (System.Runtime.InteropServices.ComTypes.IPersistFile) document;
            string tempfile = Path.GetTempFileName();
            ipersistfile.Save(tempfile, false);

            using(var stream = File.Open(tempfile, FileMode.Open, FileAccess.Read, FileShare.Read)) {
            //do something with the stream
            }

你可能感兴趣的:(VSTO实现读取WORD字节流)