Display PDF, Word or Excel Files


Simply specify the table, field and record identifier to open files stored in a database.

March 12, 2008
Iron Speed Designer V5.X

Procedure

You can easily enhance your application to open files stored in a database when your users click a link. Using a built-in feature that retrieves binary data, you simply specify the table, field and record identifier to retrieve the file.

Start by embedding this link in your HTML layout page file, e.g.:

<a href='..\Shared\ExportFieldValue.aspx?Table=<GEN:FieldValue NAME="TABLENAME"
/>&Field=<GEN:FieldValue NAME="FIELDNAME" />&Record= <GEN:FieldValue
NAME="RECORDIDFIELD" />' target="_blank">Open File</a>

The ExportFieldValue.aspx page is used to extract the data. Iron Speed Designer automatically creates this page and places it within your application's Shared folder. The ASPX version of this page has BaseClasses tags that enable it to extract the field's data given a table name and record ID.

Step 1: After placing the above link into your HTML layout page file, go to the Design tab in Iron Speed Designer and select Tools, Page Properties to display the Properties dialog. Click "Show Tree" at the bottom to see all the code generation tags on the left. Navigate to the TABLENAME, and go to the Bindings tab and bind this to any text field of the record being displayed, for example to CategoryName in Categories table, or LastName in Employees and so on. Make sure, that 'Save field value to database' checkbox on Display tab is not checked. Repeat the same procedure for FIELDNAME and RECORDIDFIELD (you can bind them to the same text field).

Step 2: Rebuild application.

Step 3: Open the corresponding Control file in the App_Code folder in Application Explorer. For example, if you placed your customization in ShowCategoriesTablePage.html, open:

...\App_Code\Categories\ShowCategoriesTablePage.Control.cs (.vb)

Step 4: Add the following method In the Section 1 region of the ControlRow class (e.g., CategoriesTableControlRow):

C#

public override void DataBind(){
    base.DataBind();
    if (this.DataSource == null){ return; }
    this.FIELDNAME.Text = ((BaseApplicationPage)(this.Page)).Encrypt("Picture");
    this.TABLENAME.Text = ((BaseApplicationPage)(this.Page)).Encrypt("Categories");
    this.RECORDIDFIELD.Text = ((BaseApplicationPage)(this.Page)).Encrypt
    (this.DataSource.Format(CategoriesTable.CategoryID)); }

Visual Basic .NET:

Public Overrides Sub DataBind()
    MyBase.DataBind()
    If Me.DataSource Is Nothing Then
        Return
    End If
    Me.FIELDNAME.Text = CType(Me.Page,BaseApplicationPage).Encrypt("Picture")
    Me.TABLENAME.Text = CType(Me.Page,BaseApplicationPage).Encrypt("Categories")
    Me.RECORDIDFIELD.Text =
        CType(Me.Page,BaseApplicationPage).Encrypt(Me.DataSource.Format(CategoriesTable.CategoryID))
End Sub

Put the name of your specific field in place of "Picture" and the name of your table in place of "Categories"you're your record row ID in place of CategoriesTable.CategoryID so the Data Access Layer can retrieve the exact row. You can use a different parameter order if desired.

If you add the FileName parameter to open a file, then your HTML will look like:

<a href='..\Shared\ExportFieldValue.aspx?Table=<GEN:FieldValue NAME="TABLENAME" />&Field=<GEN:FieldValue NAME="FIELDNAME" />&FileName= <GEN:FieldValue NAME="FILENAME" />&Record= <GEN:FieldValue NAME="RECORDIDFIELD" />' target="_blank">Open File</a>

And in code you would add is:

C#:

this.FILENAME.Text = "YourFileNameValue";

Visual Basic .NET:

Me.FILENAME.Text = "YourFileNameValue"

Note, that 'FileName' is not decrypted by the ExportFieldValue, so do not encrypt it like other arguments.

Step 5: Build and run your application. A link is displayed that, when clicked, will open the file in the appropriate program.

About the Author

Alan S. Fisher
Co-Founder and Chairman of Iron Speed, Inc.

Mr. Fisher was a General Partner at Outlook Ventures, Inc., a venture capital company prior to co-founding Iron Speed, Inc. He co-founded Onsale, Inc. (now part of Amazon) and was its Chief Technology Officer from July 1994 to December 1999. He also co-founded and was President of Software Partners, Inc, a developer and publisher of software products from August 1988 to July 1994. From April 1984 to August 1988, Mr. Fisher served as Technical Marketing Manager and Product Development Manager for Teknowledge, Inc., a developer of artificial intelligence software products. From June 1981 to April 1984, he served as a member of the technical staff for AT&T Bell Laboratories.

Mr. Fisher has served on the boards of several publicly traded companies including Onsale, Inc. (NASDAQ:ONSL), an Internet auction retailer; Egghead.com (NASDAQ:EGGS), an Internet retailer of computers and software; FatBrain, Inc. (NASDAQ:FATB), an Internet retailer of technical and professional books; and Infodata Systems Inc. (NASDAQ:INFD), an e-business consulting services company.

Mr. Fisher received his B.S. in Electrical Engineering from the University of Missouri and received his M.S. in Electrical Engineering from Stanford University.



  Privacy Statement