asp.net - file upload hasfile equivalent -


i'm looking equivalent of hasfile. not using asp control asp:fileupload.

my html looks this:

<input type="file" id="imagen" name="imagen" runat="server"/> 

i have enctype="multipart/form-data" on form.

my code behind looks this:

nombrefichero = imagen.postedfile.filename fileextension = system.io.path.getextension(nombrefichero)  imagen.postedfile.saveas(path & id_foto & fileextension) 

this works perfecty if select file. has explained on title of question need equivalent of using hasfile check if selected file.

this i've tried far

if imagen.postedfile.contentlength > 0      nombrefichero = imagen.postedfile.filename      fileextension = system.io.path.getextension(nombrefichero)      imagen.postedfile.saveas(path & id_foto & fileextension) end if 

the code above doesn't work since if statement catches exception. need check if there file selected before doing

postedfile.saveas


Comments