Updated March 12, 2008
Iron Speed Designer V5.1
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 <yourtable>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.
Part V: Customizing Generated Application Code