Mēģinām augšuplādēt (upload) failu ASP.net lapā. Priekš tam lapas kodā jāievieto apmēram šāds:
<input id="myFile" type="file" runat="server" />
<input type=button id="cmdUp" runat="server" />
Pēc tam varam ķert notikumu, kad nospiesta upload poga. Pēc MSDN rādītā piemēra, pietiek pārbaudīt vai UploadedFile atribūts nav nothing, tas ir, šādi:
Private Sub Uploads (ByVal s As System.Object, ByVal e As System.EventArgs) Handles cmdUp.ServerClick
If Not Me.myFile.PostedFile Is Nothing Then
'... darām kaut ko
End If
End Sub
Tomēr patiesībā “Not Me.myFile.PostedFile is Nothing” vienmēr atgriež True – pat tad, ja faila nav. Vismaz pie konfigurācijas, kāda tā ir man. Līdz ar to vienīgais veids, kā pārbaudīt, ka tiešām kaut kas ir uploadēts, ir:
Private Sub Uploads (ByVal s As System.Object, ByVal e As System.EventArgs) Handles cmdUp.ServerClick
If (Not Me.myFile.PostedFile Is Nothing) AndAlso _
(Me.myFile.PostedFile.ContentLength>0) Then
'... darām kaut ko
End If
End Sub
Tā, redz!