Step 1: Add a Literal control to TableControlRow
Drag and drop a Literal control (non data-bound) alongside the File Upload control (Fig. 4). Name it "FilePath".
Note the hidden control "ATCH_FILENM" stores the file name to the database, and the FileDeleteButton. The FileDeleteButton
removes the posted file and cancels its upload.

Figure 4. Add a Literal control alongside the File Upload control.
Step 2: Add a PreRender event handler to switch the visibilities of the controls
In the MyTableControlRow class (in file: ...\<App Name>\App_Code\MyFolder\MyPage.Controls.cs or .vb), insert
the following code.
C#:
public MyTableControlRow(){
PreRender += new EventHandler(MyTableControlRow_PreRender);
}
private void MyTableControlRow_PreRender(object sender, EventArgs e){
if(ATCH_FILE.PostedFile != null && ATCH_FILE.PostedFile.FileName.Length > 0){
// Save PostedFile to a session variable
Page.Session[FilePath.ClientID] = ATCH_FILE.PostedFile;
// Also set filename to ATCH_FILENM
string fullPath = ATCH_FILE.PostedFile.FileName;
int LastIndex = fullPath.LastIndexOf("\\");
ATCH_FILENM.Text = fullPath.Substring((LastIndex + 1));
}
// Show Literal if PostedFile is in the session variable.
if(Page.Session[FilePath.ClientID] != null) {
FilePath.Text = ((HttpPostedFile)Page.Session[FilePath.ClientID]).FileName;
FilePath.Visible = true;
ATCH_FILE.Visible = false;
}else{ // Otherwise, show the FileUpload
FilePath.Visible = false;
ATCH_FILE.Visible = true;
}
}
|
Visual Basic .NET:
Public Sub New()
AddHandler PreRender, AddressOf MyTableControlRow_PreRender
End Sub
Private Sub MyTableControlRow_PreRender(ByVal sender As Object, _
ByVal e As EventArgs)
If Not ATCH_FILE.PostedFile Is Not Nothing AndAlso _
ATCH_FILE.PostedFile.FileName.Length > 0 Then
‘ Save PostedFile to a session variable
Page.Session(FilePath.ClientID) = ATCH_FILE.PostedFile
‘ Also set filename to ATCH_FILENM
Dim fullPath As String = ATCH_FILE.PostedFile.FileName
Dim LastIndex As Integer = fullPath.LastIndexOf("\\")
ATCH_FILENM.Text = fullPath.Substring((LastIndex + 1))
End If
‘ Show Literal if PostedFile is in the session variable.
If Not Page.Session(FilePath.ClientID) Is Not Nothing then
FilePath.Text = _
(DirectCast(Page.Session(FilePath.ClientID), HttpPostedFile)).FileName
FilePath.Visible = True
ATCH_FILE.Visible = False
Else
‘ Otherwise, show the FileUpload
FilePath.Visible = False
ATCH_FILE.Visible = True
End If
End Sub
|
Step 3: Override FileDeleteButton_Click event handler
While still in the MyTableControlRow class, add the following code to remove the posted file from the session if
the user discards the file.
C#:
public override void FileDeleteButton_Click(object sender,
ImageClickEventArgs args){
base.FileDeleteButton_Click(sender, args);
this.Visible = false;
this.Page.Session.Remove(FilePath.ClientID);
}
|
Visual Basic .NET:
Public Overloads Overrides Sub FileDeleteButton_Click(ByVal sender As Object, ByVal args As ImageClickEventArgs)
MyBase.FileDeleteButton_Click(sender, args)
Me.Visible = False
Me.Page.Session.Remove(FilePath.ClientID)
End Sub
|
Step 4: Override GetUIData() for uploading the file
Again in the MyTableControlRow class, insert the following code.
C#:
public override void GetUIData(){
HttpPostedFile file = null;
if (ATCH_FILE.PostedFile != null &&
ATCH_FILE.PostedFile.FileName.Length > 0 &&
ATCH_FILE.PostedFile.ContentLength > 0)
file = ATCH_FILE.PostedFile;
else
file = Page.Session[FilePath.ClientID] as HttpPostedFile;
if(file != null){
DataSource.Parse(MiscUtils.GetFileContent(file), MyTable.ATCH_FILE);
DataSource.Parse(HttpUtility.HtmlDecode(ATCH_FILENM.Text),
MyTable.ATCH_FILENM);
}
}
|
Visual Basic .NET:
Public Overloads Overrides Sub GetUIData()
Dim file As HttpPostedFile = Nothing
If Not ATCH_FILE.PostedFile Is Not Nothing AndAlso _
ATCH_FILE.PostedFile.FileName.Length > 0 AndAlso _
ATCH_FILE.PostedFile.ContentLength > 0 Then
file = ATCH_FILE.PostedFile
Else
file = TryCast(Page.Session(FilePath.ClientID), HttpPostedFile)
End If
If Not file is Not Nothing Then
DataSource.Parse(MiscUtils.GetFileContent(file), MyTable.ATCH_FILE)
DataSource.Parse(HttpUtility.HtmlDecode(ATCH_FILENM.Text), _
MyTable.ATCH_FILENM)
End If
End Sub
|
Step 5: Rebuild and run
Here is what it looks like (Fig. 5).

Figure 5. Upload multiple files in Iron Speed Designer generated app.
|