Asp.net| Upload | Design |asp.net| upload <% @ Import namespace= "System.IO"%>
<body >
<script LANGUAGE = "VB" RUNAT = "SERVER" >
Sub uploadfile_clicked (Sender as Object, e as EventArgs)
Dim Lstrfilename As String
Dim Lstrfilenamepath As String
Dim Lstrfilefolder As String
' If the upload directory is empty, use ' C:\ "As the default upload directory
' Get the directory name uploaded to the server
If Dir.value <> "" Then
Lstrfilefolder = Dir.value
Else
Lstrfilefolder = "C:\"
End If
' Get file name
Lstrfilename = LoFile.PostedFile.FileName
' Note: LoFile.PostedFile.FileName returns the
File name selected through the file dialog box, which contains the directory information for the file
Lstrfilename = Path.getfilename (lstrfilename)
' Remove directory information, return file name
' To determine whether an uploaded directory exists or not, to establish
If (not directory.exists (Lstrfilefolder)) Then
Directory.CreateDirectory (Lstrfilefolder)
End If
' Uploading files to the server
Lstrfilenamepath = Lstrfilefolder & Lstrfilename
' Get uploaded directory and file name
LoFile.PostedFile.SaveAs (Lstrfilenamepath)
' Get and display the properties of the uploaded file
Filename.text = Lstrfilename
' Get file name
Filetype.text = LoFile.PostedFile.ContentType
' Get file type
Filelength.text = CStr (loFile.PostedFile.ContentLength)
' Get file length
Fileuploadform.visible = False
Answermsg.visible = True
' Show upload file properties
End Sub
</script >
<asp:panel id = "Fileuploadform" visible = "true" runat = "server" >
<form method = "POST" enctype = "multipart/form-data" runat = "server" >
Please select the name of the file to upload to the server:
<input id = "Lofile" type = "file" runat = "server" > <BR >
Please enter the name of the directory to upload to the server:
<input id = "dir" type = "text" runat = "server" > <BR
<input type = "submit" value = "start uploading" OnServerClick = "
uploadfile_clicked "runat =" server ">
<BR >
</form >
</asp:panel >
<asp:panel id = "answermsg" visible = "false" runat = "server" >
Thank you for using ASP.net page to implement file upload <BR >
Successfully uploaded <asp:label id = "FileName" runat = "server"/> <BR
File size <asp:label id = "Filelength" runat = "server"/> byte <br > file type <asp:label id = "FileType" runat = "server"/> <BR
</asp:panel >
</body >