How to convert an Interop.Word.Document object to a stream or byte array?


I'm trying to upload a word document I have created in memory to Sharepoint 2010 and it looks like the only way to do this is to convert it to a byte array or a stream. Is there anyway I can do this <strong>without</strong> saving it to disk first?


this link: <a href="http://social.msdn.microsoft.com/forums/en-US/vsto/thread/84f1ac3f-f078-4087-a627-351d6bb57173/" rel="nofollow">http://social.msdn.microsoft.com/forums/en-US/vsto/thread/84f1ac3f-f078-4087-a627-351d6bb57173/</a>

suggests that the correct way is to either

<ul><li>copy the document to the clipboard, then stream the data off the clipboard, or...</li> <li>read the document Range's XML.</li> </ul>


Cast the document to the IPersistFile interface, and then simply perform the "Save(path,false)" method:

var iPersistFile = (IPersistFile)this.Application.ActiveDocument; iPersistFile.Save("[path]",false);

All credit goes to these guys:

<a href="http://blogs.msdn.com/b/pranavwagh/archive/2008/04/03/how-to-do-a-save-copy-as-in-word.aspx" rel="nofollow">http://blogs.msdn.com/b/pranavwagh/archive/2008/04/03/how-to-do-a-save-copy-as-in-word.aspx</a>

<a href="https://social.msdn.microsoft.com/Forums/vstudio/en-US/84f1ac3f-f078-4087-a627-351d6bb57173/how-to-get-document-content-in-byte-array?forum=vsto" rel="nofollow">https://social.msdn.microsoft.com/Forums/vstudio/en-US/84f1ac3f-f078-4087-a627-351d6bb57173/how-to-get-document-content-in-byte-array?forum=vsto</a>


  • Solve the error installation package is not supported by this processor type
  • how to know which word version is installed from my add-in (Ribbon)? with c#
  • zeroclipboard element not working when located inside secondary/non-default jQuery tab
  • Get Office Addin Publish Version
  • C# Paste HTML to Excel or PowerPoint
  • Clipboard is not set after application exits?
  • how to copy a text to the Clipboard in android [duplicate]
  • Is there any Web API for Google web clipboard?
  • Copy only selected rows without not-selected rows between in RowHeaderSelect mode
  • Why my StringReplace don't work?
  • VSTO - Best place to store Excel workbook settings
  • Custom User Control in C#…Right Click Menu to Copy Text (Java Developer learning C#)
  • Jquery - Copy div contents to clipboard
  • How do you copy the contents of a Cell into the Clipboard
  • How to add brackets using AutoHotKey
  • How to work with Clipboard in ASP.NET, Server side
  • Filter android ListView with predefined filters
  • Hibernate manyToOne filter on base entity
  • Dump all Raima db_VISTA Version 3.20 data to text
  • Error Installing Windows 10 development tools for Visual Studio 2015 RC on Windows 8.1
  • Compress a file with GZipStream while maintaining its meta-data
  • powershell Get-Counter -ComputerName parameter on Windows 7
  • Xamarin MonoAndroid Azure mobile service InsertAsync
  • How can I include If-None-Match header in HttpRequestMessage
  • Private IP address in reserved subnet range
  • How To Customize ASP.NET Chart Databound To SqlDataSource
  • Enabling DTD support in Sql Server
  • UWP/C# - Issue with AQS and USB Devices
  • Web.config system.webserver errors
  • Parse a date string in a specific locale (not timezone!)
  • How to determine if there are bytes available to be read from boost:asio:serial_port
  • Unity3D & Android: Difference between “UnityMain” and “main” threads?
  • Retrieving value from sql ExecuteScalar()
  • Display issues when we change from one jquery mobile page to another in firefox
  • Spray.io: When (not) to use non-blocking route handling?
  • Do I've to free mysql result after storing it?
  • Function pointer “assignment from incompatible pointer type” only when using vararg ellipsis
  • 0x202A in filename: Why?
  • Hibernate gives error error as “Access to DialectResolutionInfo cannot be null when 'hibernate.
  • File not found error Google Drive API