2010年11月15日

VB.NET上傳檔案

以下展示upload元件用法:
'.vb
Protected Sub btnFileUpload_Click(ByVal sender As Object,
 ByVal e As System.EventArgs)
If myFileUpload.HasFile Then
   myFileUpload.SaveAs(Server.MapPath("uploads/" & myFileUpload.FileName))
End If
End Sub

呼叫SaveAs把檔名存起來
'.vb
Protected Sub btnFileUpload_Click(ByVal sender As Object, 
ByVal e As System.EventArgs)
If myFileUpload.HasFile Then
  myFileUpload.SaveAs(Server.MapPath("uploads/" & myFileUpload.FileName))
End If
End Sub
取得上傳完整路徑和檔案:
myFileUpload.PostedFile.FileName
取得檔名
myFileUpload.FileName
參考:
http://msdn.microsoft.com/zh-tw/library/system.web.ui.webcontrols.fileupload(VS.80).aspx

2 則留言: