ASP. NET design FTP File Upload solution, asp. netftp File Upload

Source: Internet
Author: User
Tags ftp file

ASP. NET design FTP File Upload solution, asp. netftp File Upload

If ASP is used as a page for uploading FTP files, I think many people will immediately think of using third-party components, although it is relatively easy to develop. However, third-party components downloaded for free have certain functional limitations. To buy genuine third-party components, the cost for domestic users is not small, it is something that can be undertaken, and complicated procedures also make many people discouraged. Although Microsoft provides a component in its own windows system that can be used to upload files-Posting Acceptor. However, friends who have used this component all have a general feeling that it is not easy to use.
Now, it's okay, since the launch of Microsoft.. Net FrameWork. ASP. NET has already set up the file upload function internally, and this function is free of charge, and it is quite easy to use. The following example shows how to use ASP. NET to upload files.

I. software compiling and running environment
Microsoft Windows 2000 Professional Edition and. Net FrameWork SDK BETA2 (software development kit developed by Microsoft for. Net development to test version 2 ). If the hard disk partition of the running server is NTSF, set the access attribute of all hard disks on the server to Everyone to ensure that the uploaded files can be correctly written to the server's hard disk.

Ii. basic functions of the software
This software mainly uploads local files to the specified directory on the server. In the software running interface, after you select the name of the file to be uploaded, enter the name of the directory to be uploaded to the server, if not, use the default directory "C: \". If the entered directory does not exist on the server, create this directory. After you press the start upload button, the software uploads the selected file to the specified directory and returns the information of the uploaded file, that is, the name of the file, file size and type. The specific operation interface and running result interface of the software are shown in:

 

Figure 1: software operation interface

 

Figure 2: software running result Interface

3. Important steps and specific solutions in Software Design
(1) Select the local file to be uploaded to the server
First of all, thanks to the powerful functions of ASP. NET, the HTML control component provided by ASP. NET makes it easy for us to select the file to be uploaded through a dialog box. Of course, your browser must also be IE 3.02 or Netscape 3.0 or later. You can use the following statements to select a local file:
<Input id = "loFile" type = "file" runat = "server">
(2 ). to upload a file successfully, you must use "multipart/Form-data" in the form encoding instead of the default From encoding "application/x-www-form-urlencoded ".The Code is as follows:
<Form method = "post" enctype = "multipart/form-data" runat = "server">
</Form>
(3) obtain the name of the uploaded file and several operations on the disk
To obtain the name of the uploaded file, you must introduce a namespace (NameSapce) -- System. IO. This namespace defines many classes for file and disk operations. In this software, some methods and attributes of these classes are used to complete some functions of the software.
(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 in the file dialog box,
This includes the directory information of the file.
LstrFileName = Path. GetFileName (lstrFileName)
'Remove the directory information and return the file name
(2) Determine whether the upload directory exists. If it does not exist, create
To create a Directory, you must use the CreateDirectory method in the Directory class to determine whether the Directory Exists and the Exists method in the Directory class. The details are as follows:
If (not Directory. Exists (lstrFileFolder) Then
Directory. CreateDirectory (lstrFileFolder)
End If
'Note: lstrFileFolder is the directory name you enter or the default directory name.
(4) Upload the selected file to the server
After the previous work has been completed, you can upload the file. It is relatively simple to upload the file. You can use the following two statements to complete the upload.
LstrFileNamePath = lstrFileFolder & lstrFileName
'Get the upload directory and file name
LoFile. PostedFile. SaveAs (lstrFileNamePath)
'Upload files to the server
(5). Obtain and display the attributes of the uploaded file
FileName. Text = lstrFileName
'Get the file name
FileType. Text = loFile. PostedFile. ContentType
'Obtain the file type
FileLength. Text = cStr (loFile. PostedFile. ContentLength)
'Get the file length
FileUploadForm. visible = false
AnswerMsg. visible = true
'Display uploaded file attributes
The above are some important aspects of the software.

4. program source code

<% @ Import Namespace = "System. IO "%> 

V. Summary
So far, we have completed all the work of a relatively complete FTP file upload software. It can be seen that ASP. NET is still quite powerful. In this example, we can also see that you want to use ASP flexibly. NET, but also have a deep understanding of Microsoft.. net framework software development kit (sdk beta 2), only master. net framework development software development kit, can use ASP. NET has developed software with more powerful functions and greater vitality.

The above is the use of ASP. NET to design the FTP File Upload process, hope to be familiar with ASP. NET Design FTP File Upload is helpful.

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.