Asp. NET design ftp File Upload Solution _ Practical skills

Source: Internet
Author: User
Tags ftp file

If you want to use ASP to make an FTP file upload page, I think many people immediately think of the use of third-party development of components, the use of Third-party components, although relatively easy to develop. But in general, the free download of third-party components have certain aspects of the functional limitations, to purchase genuine Third-party components, for domestic users, the cost is also a large number, is able to bear, tumultuous procedures also make many people deterred. Although Microsoft also provides a component--posting acceptor that can be used to upload files in its own Windows system. But friends who have used this component have a common feeling that it's not working.
Well now, since Microsoft launched the. NET Framework, the ASP.net, which is an important part of the. NET Framework, has built a file upload function internally, and this feature is both free and quite useful. Here's an example of how you can use the ASP.net feature to complete file uploads.

A Software Authoring and operating environment
Microsoft Windows 2000 Professional Edition and the. Net FrameWork SDK BETA2 (developed by Microsoft. NET developed software development package test version 2). If the hard disk partition of the server that is running is the NTSF partition, set the Access property of all the hard disks on the server to everyone, which ensures that the uploaded files are correctly written to the server's hard disk.

Two The basic function of software
This software mainly completes the function of uploading local files to the server's specified directory. In the software's running interface, after the user chooses to upload the file name, fill in the directory to upload to the server after the name, if not filled up to the server directory, then use the default directory "C:\ , this directory is established if the directory you are filling does not exist on the server. After pressing the "Start upload" button, the software uploads the selected file to the specified directory, and then returns the information for the uploaded file, which is the name of the file, the size of the file, and the type of file. The specific operating interface of the software and the running result interface are shown in the following illustration:

Figure 1: The operating interface of the software

Figure 2: Running results interface for software

three. Important steps in software design and specific solutions
(i). 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:

(ii). In order to successfully complete the file upload work, in the form The encoding in must be "multipart/form-data" instead of the default encoding "Application/x-www-form-urlencoded" from. the specific code is as follows:



(c). Get uploaded file name and several operations on disk
you must introduce a namespace (NAMESAPCE)--system.io in order to obtain the uploaded file name. 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.post Edfile.filename returns the file name selected by the file dialog box,
which contains the directory information for the file
Lstrfilename = Path.getfilename (lstrfilename)
' Remove directory information , return the file name
(2). To determine whether an uploaded directory exists or not, set up a directory to use the CreateDirectory method in the Directory class to determine if the directory exists to use the DirectoThe Exists method in the Ry class. Details are as follows:
If (not directory.exists (lstrfilefolder)) Then
Directory.CreateDirectory (lstrfilefolder)
End I F
' Note: Lstrfilefolder is the directory name that the user fills in, or the default directory name
(iv). 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
' gets uploaded directory and file name
LoFile.PostedFile.SaveAs (lstrfilename Path)
Upload files to server
(v). Obtain and display the properties of the uploaded file
Filename.text = lstrfilename
' Get file name
Filetype.text = LoFile.PostedFile.ContentType br> ' Get file type
Filelength.text = cStr (loFile.PostedFile.ContentLength)
' get file length
Fileuploadform.visible = Fal Se
Answermsg.visible = True
' show upload file properties
These are some of the more important parts of the software in writing.

four. Program source code

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

Welcome to ASP . NET page implementation file Upload

Please select the file name to upload to the server:
Please enter the directory name to upload to the server:

Thank you for using ASP.net page to implement file upload
successful upload
file size byte

Five Summarize
At this point we have completed a relatively perfect FTP file upload software All the work, this shows that the function of ASP.net is still relatively strong. With this example, we also see that in order to use ASP.net flexibly, the software development kit developed by Microsoft for the. NET Framework (SDK BETA 2) is mastered, and only the software development package developed by the. NET Framework is available, It is possible to use ASP.net to develop more powerful, more vital software.

The above is the use of asp.net design ftp file Upload all the process, I hope to master the design of asp.net ftp file upload help.

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.