In this article, I will explain how to uplaod files using ASP.NET ,VB.NET.It is a simplest way of uploading the files.
Using ASP.NET, you can upload the files respectively. they are
First thing you have to add the file filed control from HTML Controls from the toolbox.
add runat=server control property to the control
on the Form tag add the parameter encType="multipart/form-data".
The following Inlinecode explains the concepts as follows.
<%@ Page Language="VB"%>
<%@ Import Namespace="System.Threading" %>
<html>
<head>
<title>Simplest way to uplaod files in ASP.NET</title>
</head>
<script runat="server">
Protected Sub Upload(ByVal sender As Object, ByVal e As System.EventArgs)
if FileUpload1.FileName <> "" then
FileUpload1.SaveAs(Server.MapPath("~/upload/") + FileUpload1.FileName)
Dim p As New Photo(ddcollections.SelectedValue, txtName.Text,
FileUpload1.FileName, txtDesc.Text)
If txtDesc.Text <> "" And txtName.Text <> "" Then
'hand off the new photo to the data access class
Dim result As Boolean = PhotoDB.InsertPhoto(p)
If result = True Then
Label1.Text = "File upload completed! "
ddcollections.SelectedIndex = 0
txtDesc.Text = ""
txtName.Text = ""
Else
Label1.Text = "File upload did not complete successfully"
End If
End If
end if
End Sub
</script>
<form enctype="multipart/form-data" runat="server">
Select the photo you would like to share:<br />
<asp:FileUpload ID="FileUpload1" runat="server" Width="317px" />
<br />
<br />
<asp:TextBox ID="txtName" runat="server" Width="217px"></asp:TextBox>
Name<br />
<br />
<br />
<asp:TextBox ID="txtDesc" runat="server" Height="85px" Width="228px" TextMode="MultiLine"></asp:TextBox>
Description<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Upload" OnClick="Upload" />
<br />
<br />
<asp:Label ID="Label1" runat="server"></asp:Label> <br />
<br />
<asp:LinkButton ID="LinkButton1" runat="server" PostBackUrl="../secure/admin.aspx">Back to Admin...</asp:LinkButton><br />
</form></body></html>
Enjoy coding ,
Thanx