Three The important steps in software design and the concrete solutions
One. Select the file to upload to the server locally
First of all, thanks to the powerful features of ASP.net, he provided the HTML control elements, making it easy for us to select the file to upload through a dialog box. Of course, your browser must also be IE 3.02 or Netscape 3.0 version or a higher version of the browser. You can complete the work of selecting a local file by using the following statement:
<input id = "Lofile" type = "file" runat = "server" >
Two. In order to successfully complete the file upload, the encoding in form must be "multipart/form-data" instead of the default encoding "Application/x-www-form-urlencoded" from. The specific code is as follows:
Three. Get the uploaded file name and some action on the disk
In order to obtain the uploaded file name, a namespace (NAMESAPCE)--system.io must be introduced. This namespace defines a number of classes on file and disk operations, in which some of the features of the software are accomplished through some of the methods and properties of these classes.
(1). Get the name of the uploaded file
Use the GetFileName method in the path class, as follows:
Lstrfilename = LoFile.PostedFile.FileName
' Note: LoFile.PostedFile.FileName returns the file name selected through the file dialog box,
This contains the directory information for the file
Lstrfilename = Path.getfilename (lstrfilename)
' Remove directory information, return file name
(2). To determine whether the upload directory exists, does not exist on the establishment
Create a directory to use the CreateDirectory method in the Directory class to determine if the directory exists to use the Exists method in the Directory class. Specifically as follows:
If (not directory.exists (Lstrfilefolder)) Then
Directory.CreateDirectory (Lstrfilefolder)
End If
' Note: Lstrfilefolder is the directory name that the user fills in, or the default directory name
Four. Upload selected files to the server
Before the work has been completed, you can upload files, upload files relatively simple, use the following 2 lines of statements can be completed upload work.
Lstrfilenamepath = Lstrfilefolder & Lstrfilename
' Get uploaded directory and file name
LoFile.PostedFile.SaveAs (Lstrfilenamepath)
' Uploading files to the server
Five. To obtain 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
The above is the software in the preparation of some of the more important places.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.