FormView Inserting event with FileUploader control

R

RosH

Dear All,

Please find below an Inserting Event code expected to trigger just
before the insert event of a FormView control. Everything works just
fine but the event throws an exception that the parameter Filename is
null. As you can see in the code that I have tried to update the
UploadedFileName textbox which is bound to the Filename column of the
database connection. During execution of the command, it is not found
to update the UploadedFileName textbox's text property even though I
have explicitly declared the textbox variable "MyUploadedFileName".
Please help me out.

Protected Sub FormView1_ItemInserting(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.FormViewInsertEventArgs) Handles
FormView1.ItemInserting

Dim MyUploadedFileName As TextBox =
FormView1.FindControl("UploadedFileName")

Dim path As String = Server.MapPath("~/UploadedImages/")
Dim fileOK As Boolean = False
If FileUpload1.HasFile Then
Dim fileExtension As String
fileExtension = System.IO.Path. _
GetExtension(FileUpload1.FileName).ToLower()
Dim allowedExtensions As String() = _
{".jpg", ".jpeg", ".png", ".gif"}
For i As Integer = 0 To allowedExtensions.Length - 1
If fileExtension = allowedExtensions(i) Then
fileOK = True
End If
Next
If fileOK Then
Try
FileUpload1.PostedFile.SaveAs(path & _
FileUpload1.FileName)
MyUploadedFileName.Text =
FileUpload1.FileName.ToString()
Catch ex As Exception
Label1.Text = "File could not be uploaded."
End Try
Else
Label1.Text = "Cannot accept files of this type."
End If
End If
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top