ASP.net upload files in the operation
Author: abigfrog (Millennium Wizard) (★ JAVA ★)
<1>. Choosing local to the server to upload the document
First of all to thank the power of ASP.NET, he provided HTML control devices, it is easy to make the adoption of a dialog box to choose to upload files. Of course, you must also be browser is IE 3.02, or Netscape version 3.0 or higher than that the two versions of the browser. The adoption of the following statement can be completed choose a local paper:
<input Id = "loFile" type = "file" runat = "server">
<B>. In order to successfully complete the file upload, in the Form of coding must be "multipart / form-data", instead of the default coding From "application / x-www-form-urlencoded." Specific code as follows:
<form Method = "post" enctype =" multipart/form-data "runat =" server ">
</ Form>
<3>. Access to your file names and the number of disk operations
In order to obtain your file name, must be the introduction of a name space (NameSapce) - System. IO. This name inside definition of a lot of space on the document and the disk-like operation, in this software category is through some of these methods and properties to complete some of the features in the software.
(1). Upload files was the name of
Path used in category GetFileName method, as follows:
LstrFileName = loFile.PostedFile.FileName
'Note: loFile.PostedFile.FileName the return of documents by file name dialog choice,
This included in the directory information
LstrFileName = Path.GetFileName (lstrFileName)
'Directory information removed and returned to the file name
(2). Determine whether there upload directory does not exist on the establishment of
To be used to build directory in the Directory of CreateDirectory, judge whether there directory to use the Directory category Exists method. As follows:
If (not Directory.Exists (lstrFileFolder)) Then
Directory.CreateDirectory (lstrFileFolder)
End If
'Note: lstrFileFolder users fill in the name of the directory, or is the default directory name
<4>. Upload the selected file to the server
In front after the work has been completed, we can upload files, and relatively simple to upload files, use the following statement on the second line upload work to be completed.
LstrFileNamePath = lstrFileFolder & lstrFileName
'Get upload directory and file name
LoFile.PostedFile.SaveAs (lstrFileNamePath)
'Upload files to the server
<5>. Upload file access and display the attributes
FileName.Text = lstrFileName
'Access to the file name
FileType.Text = loFile.PostedFile.ContentType
'Type of access to documents
FileLength.Text = cStr (loFile.PostedFile.ContentLength)
'Access to documents length
FileUploadForm.visible = false
AnswerMsg.visible = true
'Show Upload file attributes
That is the time of the preparation of this software in some of the more important areas.
You can judge in the proceedings users to upload file types:
———————–
'Type of access to documents
FileType.Text = loFile.PostedFile.ContentType
———————–
And then decide whether to accept or reject.








0 Comments to “ASP.net upload files in the operation”
No Comments. Send your comment.
Leave a Reply
You must be logged in to post a comment.