Print Search Rate
    
   10-17-2007, 12:33 PM
HOW TO: Stream SpreadBuilder Output in ActiveReports for .NET 3.0
Attachment: StreamginSpreadBuilderARN3.zip
The attached sample demonstrates how to use the SpreadBuilder API on the web to create and stream Excel documents to the user's browser on the fly.  When the page is loaded, a DataTable is returned from the database and a SpreadBuilder worksheet is built.  
sb.Save(mStrm);

The sample projects use the Northwind database, which is install by default at C:\Program Files\Data Dynamics\ActiveReports for .NET 3.0\Data\NWIND.MDB.

Sb.Save(mStrm) will save the SpreadBuilder object to XLS format.  We are placing this in a memory stream object so that we can send it to the client.

[VB.NET]
Response.Clear()
Response.ContentType = "application/x-excel"
Response.AddHeader("content-length", mStrm.Length.ToString())
Response.AddHeader("content-disposition", "inline; filename=OrigProd.xls")
Response.BinaryWrite(mStrm.ToArray())


[C#]
Response.Clear();
Response.ContentType = "application/x-excel";
Response.AddHeader("content-length", mStrm.Length.ToString());
Response.AddHeader("content-disposition", "inline; filename=OrigProd.xls");
Response.BinaryWrite(mStrm.ToArray());


This code will configure the response header so that the XLS document can be streamed to the browser.  After the Response is formatted, BinaryWrite is used to send the file to the client.  The memory stream which contains the XLS file is converted to an Array and then passed in.

[VB.NET]
HttpContext.Current.ApplicationInstance.CompleteRequest()

[C#]
HttpContext.Current.ApplicationInstance.CompleteRequest();

Afterwards, the Request is completed.  Use the CompleteRequest() method instead of Response.End() to avoid a ThreadAbortException.  Microsoft KB312629 has more details.



Applies To:
ActiveReports for .NET 1.0
ActiveReports for .NET 2.0
ActiveReports for .NET 3.0
GrapeCity » Knowledge Base » KnowledgeBase f... » HOW TO: Stream SpreadBuilder Output in ActiveReports for .NET 3.0
Privacy Policy | Copyright © 1997-2010 - GrapeCity, inc.