還可能發生其他錯誤所以應將FileUpload方法包含在一個錯誤捕獲例程中如下所示
If FileUploadHasFile Then
Try
FileUploadSaveAs(C:\BegASPNET\WroxUnited\MatchImages\ &
FileUploadFileName)
Catch ex As Exception
LabelText = Failed because: <br/> & exMessage
End Try
LabelText = File uploaded to WroxUnited from: <br/> & FileUploadPostedFileFileName
Else
LabelText = Please select a file before clicking the Upload button
End If
在下面的試一試練習中將為用戶實現上傳圖片的功能
()在VWD中使用Web Form模板創建一個名為GalleryUploadaspx的頁面與您在前面創建的大多數頁面一樣使用sitemaster作為Master頁面選擇Visual Basic語言並將代碼放置在一個單獨的頁面中
()在Design View中從工具條添加一個FileUpload控件和一個Label控件將該標簽控件的ID設置為FileUploadRepoR並將text屬性設置為空再添加一個button控件將其text屬性設置為Upload
[] [] []
From:http://tw.wingwit.com/Article/program/net/201311/14832.html