mercredi 6 mai 2015

ASP.NET FileUpload Not working

The issue is very straightforward. Two days ago everything was working just fine but today, my FileUpload asp control doesn't work. I've made several researches but I haven't seen a code or explanation that solves my problem. This is the code I have.

I will summarize, If you need more code just ask it, I will provide it.

HTML:

<td style="text-align: left;"><asp:FileUpload id="FileUpload1" runat="server" /></td>

The FileUpload is inside a table as you can see nothing more to explain. (I am not using AJAX since I saw that the FileUpload doesn't work with AJAX without some code).

Vb.net:

ruta = ConfigurationManager.AppSettings.Get("RutaFotosDirecciones").ToString()



    id_foto = (DateTime.Now - New DateTime(1970, 1, 1)).TotalMilliseconds / 1000
    Dim path As String = Server.MapPath(ruta)
    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 & id_foto & fileExtension)
            Catch ex As Exception
            End Try
        End If
    End If

I am using the Web.config file to set up my path.

The FileUpload1.HasFIle returns false and doesn't enter the if.

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire