Friday 18 January 2008

File Upload

Add a fileupload control and a button to the .aspx page:

<asp:FileUpload ID="FileUpload1" runat="server" Height="20px" />
<asp:Button ID="btnUpload" runat="server" Text="LINK" Height="20px" />

Let's say we're uploading our files to a folder called "UPLOADS" the OnClick event for btnUpload would look like this:

Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLinkPOD.Click

Dim savePath As String
savePath = Server.MapPath("UPLOADS/")

If Me.FileUpload1.HasFile Then
fileName = Me.FileUpload1.FileName
savePath += fileName
Me.FileUpload1.SaveAs(savePath)
End If

End Sub

No comments: