FileUpload control and formView Inserting Event

Discussion in 'ASP .Net' started by RosH, May 14, 2007.

  1. RosH

    RosH Guest

    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
     
    RosH, May 14, 2007
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Islamegy®

    FormView and FileUpload

    Islamegy®, May 17, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    7,465
    Islamegy®
    May 18, 2006
  2. Chris
    Replies:
    5
    Views:
    515
    Jon Paal [MSMD]
    Mar 31, 2007
  3. RosH
    Replies:
    0
    Views:
    282
  4. =?Utf-8?B?Z292ZXI=?=

    FileUpload Control in FormView using ObjectDataSource

    =?Utf-8?B?Z292ZXI=?=, Sep 2, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    746
    =?Utf-8?B?Z292ZXI=?=
    Sep 2, 2007
  5. aboomar10
    Replies:
    0
    Views:
    124
    aboomar10
    Oct 4, 2004
Loading...

Share This Page