Open Office File From Stream - Open Word, Excel, PowerPoint without Temporary File in Server.

Edraw Office Viewer Component allows developers to open MS Word, Excel and PowerPoint document from stream.

The server has not the temporary file if you read file from database.

Download Office Viewer Component and View Sample Projects

Open Office File From Stream C# Sample Project

Open Office File Stream with the HTTP/HTTPS

boolean HttpOpenFileFromStream(BSTR WebUrl, BSTR ProgID, [in, optional] VARIANT WebUsername, [in, optional] VARIANT WebPassword);

WebUrl: A string containing the web url from which downloads data via HTTP. The WebUrl must include the file extend name so that the component knows the file type. For example:, or
ProgID: Word.Application, Excel.Application or PowerPoint.Application.
WebUsername: A string containing the user name.
WebPassword: A string containing the access password.

Either you want to open an appointed file or open a file from database, for client side, all you need to do is the same, like the following:

<script language="vbscript">
Sub DownloadFile()
EDOffice.HttpAddpostString("DocumentID", "Tester.xls");
EDOffice.HttpOpenFileFromStream("http://localhost:2440/ASPCSharp/UploadAction.aspx", "Excel.Application");
End Sub

Before you call function HttpOpenFileFromStream, you should do two things. One is to initialize http for clearing all parameters and cookies in http, another is to appoint the file or database record. And then use HttpOpenFileFromStream to send the request to the destinated webpage. Before HttpOpenFileFromStream send request, it will add a couple of parameters automatically.
EDOffice.AddPostArgument(L"EDA_GETSTREAMDATA", L"EDA_YES"); This couple of parameters tell the destinated webpage EDOffice will received file as stream.

At the web side, webpage will decide to read which file or database record according to the post parameters. And you should add boundary flag 'EDA_STREAMBOUNDARY' to file data, following is the demo.

public partial class UploadAction : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
if (Request.Params["EDA_GETSTREAMDATA"] == "EDA_YES")
//string fullFileName = Server.MapPath("testnewone.txt");
//String fs = File.ReadAllText(fullFileName);
String fullFileName = Server.MapPath(Request.Params["DocumentID"]);
Byte[] fs = File.ReadAllBytes(fullFileName);
Response.Write("Get Stream Successfully!");
if (Request.Params["author"] == "anyname" && Request.Params["Data"] == "2007-5-15")
Response.Write("We have receipted the right param from Office ActiveX Control.");
if (Request.Files.Count == 0)
Response.Write("There isn't file to upload.");
if (Request.Files[0].ContentLength == 0)
Response.Write("Failed to receipt the data.\n\n");
for (int i = 0; i < Request.Files.Count; i++)
string fullFileName = Server.MapPath(Request.Files[i].FileName);
Response.Write("Upload Successfully.");


If l_bWrSreamBoundary
Then Response.Write "EDA_STREAMBOUNDARY"
While Not l_stream.EOS And Response.IsClientConnected
Wend l_stream.Close
If l_bWrSreamBoundary


<%@ page import="*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.text.*" %>
int BUFFER_SIZE = 8*1024; // buffer size input_file = null; // input file input_stream = null; // input FileStream
String file_ext = "docx";
int idnum = 0;
idnum = com.dms.RequestParam.getParam(request, "idnum", 0);
String filename = "/webroot/_work/open/doc1.docx";
if(idnum == 222) filename = "/webroot/_work/open/doc2.docx";
ServletOutputStream http_os = null;
// get the file
input_file = new;
// get the input stream
input_stream = new;
// setup the response
http_os = response.getOutputStream();
byte[] bytes = new byte[BUFFER_SIZE];
int read = 0;
// send binary data
while((read =, 0, BUFFER_SIZE)) != -1)
http_os.write(bytes, 0, read);
catch(Exception ex)

Save MS Word to File Stream

The office viewer component can save the word document without temporary file. Firstly, you can call the WordCopyToClipboard method to save the whole document to clipboard. Then you can store into database as Image as well as in String format.


IDataObject data = Clipboard.GetDataObject();

text = data.GetData(DataFormats.Text).ToString();

//Or try this using filestream

//FileStream fstream = newFileStream("Sample.doc",FileMode.Open,FileAccess.Read);

//StreamReader sreader = new StreamReader(fstream);

//txtFileContent.Text = sreader.ReadToEnd();

Large File Http Post Upload - PHP and

Disables Office 2003 Toolbars

Disable Office Ribbon Button

Show/Hide Office Menu Bar

Integrate MS Office in Delphi Program

Embed Office in C# and Do Office Automation

Online Office Document Viewer

Get Started! Make your application display and interact with MS Office. Try Office Viewer Component