The StreamingOfficeSample.exe sample package
The StreamingOfficeSample.exe sample package contains the
following:
- A Web form
- The DocumentGenerator class library project
- The WorkBookGenerator class library project
The Web form and the class library projects were created by
using Microsoft Visual C# 2005.
The Web form
The Web form connects to the Northwind sample database that is
included with Microsoft Office Access 2003.
Note You do not have to have Office Access 2003 installed to use the
sample package.
The Web form uses data from the following tables to
display an online order lookup form:
- Customers
- Orders
- Order Details
- Products
You can use the Web form to select a customer in a list. After
you select the customer, the Web form filters the list of orders. The filtered list shows
only orders for the selected customer. When you select an order in the list, the details for the order appear in the data grid control on the Web
form. Then, you can click the buttons on the Web form to perform the following
actions:
- Create a report that is based on the selected data
The
code creates this report as a Word 2007 document and then streams the document
to the client computer. - Export the order details data to a new Excel
workbook
The code creates an Excel 2007 workbook and then streams the
workbook to the client computer.
The DocumentGenerator class library project
The code in the
DocumentGenerator class library project uses the Packaging components in the
WindowsBase.dll assembly to create the Word document. The WindowsBase.dll
assembly is included with the .NET Framework 3.0.
This class library
project contains the NwindTemplate.docx file as an embedded resource. The
Packaging components in the WindowsBase.dll assembly read the contents of the
NwindTemplate.docx file into a package object. The Packaging components use the
methods in the
clsCreateDocument class to perform the following actions:
- Create a Word 2007 document in the temporary folder on the
server
This Word document is based on the NWindTemplate.docx
file. - Add various parts and various data to the Word document
from the Web form
When the Word document is complete, the code in the
DocumentGenerator class library project streams the Word document to the client
computer.
The WorkBookGenerator class library project
The code in the
WorkBookGenerator class library project uses the Packaging components in the
WindowsBase.dll assembly to perform the following actions:
- Export the order details data to a new Excel
workbook
To do this, the Packaging components read the data into an Array list object. - Create an Excel workbook in the temporary folder on the
server
The Packaging components, together with the methods in the clsCreateWorkbook class, add the workbook parts and the data to the Excel workbook
from the Web form.
When the Excel workbook is complete, the code in the
WorkBookGenerator class library project streams the workbook to the client
computer.
Test the sample
To test the sample, you will perform the following actions:
- Add the sample project to the Web server
- On a client computer, visit the sample project Web site
that you created
- Download the Word document report and the Excel
workbook
To do this, follow these steps.
Add the sample project to the Web server
- Download the sample package file.
- Create the following folder on the Web server:
C:\Inetpub\wwwroot\StreamingOffice2007Sample
- Extract the contents of the sample package file to the
folder that you created in step 2.
- Use IIS Manager to create a virtual directory. To do this,
follow these steps:
- Click Start, click
Run, type inetmgr, and then click
OK.
- Expand the server name, and then expand Web
Sites.
- Right-click Default Web Site, point to
New, and then click Virtual
Directory. The Virtual Directory Creation Wizard starts.
- In the Virtual Directory Creation Wizard, click
Next.
- In the Alias box, type an alias for the virtual directory. For example, type
StreamingOffice2007Sample.
- Click Next.
- Click Browse, locate the folder that
you created in step 2, and then click Next.
- Click to select the Read check box
and the Run scripts (such as ASP) check box.
- Make sure that the other check boxes are cleared, and
then click Next.
- Click Finish to complete the
wizard.
For ASP content, you may want to confirm that an application was
created. To do this, follow these steps:
- Right-click the virtual directory that you created in the
previous steps, and then click Properties.
- On the Virtual Directory tab, make sure
that the virtual directory alias is listed in the Application name box under
Application Settings. If the virtual directory alias is not
listed, click Create.
Note The application name does not have to match the virtual directory
alias that you typed in step 4e of the previous steps. - Click the ASP.NET tab. Verify that
ASP.NET version is set to 2.0.50727. If it is
not, select 2.0.50727 in the ASP.NET version
list, and then click Apply.
Visit the sample project Web site, and then download the Word document report and the Excel workbook
Note The client computer that you will use for the following steps
must have one of the following installed:
- Microsoft Office Word 2007 and Microsoft Office Excel
2007
- Microsoft Office Compatibility Pack for Word, Excel, and
PowerPoint 2007 File Formats
On a client computer, follow these steps:
- Start a Web browser such as Microsoft Internet Explorer,
and then visit the following Web site:
http://ServerName/StreamingOffice2007Sample/default.aspx
Note The placeholder ServerName represents
the Web server.
The Northwind Order Form page appears. - In the Customer Name list, select a
customer.
- Select an order ID. Notice that the order details for the
order that you selected appear in the data grid control.
- Click Generate Word Report. The code in
the DocumentGenerator class library project creates a Word 2007 document and then
streams the document to the client computer.
- When the File Download dialog box appears,
click Open to open the Report.docx file. The file opens in
Word. The Word document contains an order summary for the selected
order.
- Click Export to Excel. The code in the WorkBookGenerator class library project creates an Excel 2007 workbook and then
streams the workbook to the client computer.
- When the File Download dialog box appears,
click Open to open the Report.xlsx file. The file opens in
Excel. The workbook contains a summary of the order detail information. The
summary includes the total cost of the order.