PostedFile problems

daud

New Member
Hi,<BR><BR>I'm trying to use the:<BR><BR>If not IsNothing(tbPhoto.PostedFile) then<BR>try<BR> tbPhoto.PostedFile.SaveAs("d:inetpub... etc")<BR>catch exc as Exception<BR> lblMessage.text = "Problem"<BR>end try<BR>End if<BR><BR>This works fine for the positive and successfully loads the file onto the server, but when the user doesn't enter anything into the upload field, it still tries to upload. It's as if the 'If not IsNothing(tbPhoto.PostedFile) then' isn't working - has anyone else experienced this problem.<BR><BR>Rgds<BR>Paul<BR><BR>I had the same problem. Here is what I did:<BR><BR>Dim AttachedFiles As System.Web.HttpFileCollection = System.Web.HttpContext.Current.Request.Files<BR><BR>If (AttachedFiles.Item(0).FileName <> "")<BR>'process file here.<BR>Else<BR>'No file uploaded<BR>End If<BR><BR>I tried using AttachedFiles.Count as a check as well, but it still counts the "<input type=file..." even if no data is entered into the field.<BR><BR>You can use the OR statement if you have more than one file.<BR><BR>If (AttachedFiles.Item(0).FileName <> "" OR AttachedFiles.Item(1).FileName <> "") Then<BR><BR>Cheers,<BR>David<BR><BR>That's excellent - Thank you David, much appreciated :-)<BR><BR><BR>Many Thanks<BR>Paul
 
Back
Top