ASP.NET's operation

zhaozj2021-02-16  118

ASP.NET's operation

Author: abigfrog (Millennium Elf) (★ JAVA ★)

. Select the file to be uploaded to the server

First of all, thank ASP.NET's powerful feature, he provides the HTML control component that makes it easy to pass a dialog box to select the file you want to upload. Of course your browser must also be an IE 3.02 or Netscape 3.0 or a browser that is high than this version. You can complete the work of a local file by following statements:

<2>. In order to successfully complete the file upload, encoding in the Form must use "Multipart / Form-Data" without the default code "Application / X-WWW-Form-Urlencoded" of from FROM. The specific code is as follows:

. Get uploaded file names and some operations to disk

In order to get the uploaded file name, you must introduce a namespace (namesapce) --system.io. This namespace define a number of classes with files and disk operations, in this software, through certain methods and properties of these classes to complete some of the functions in software.

(1). Name of the upload document

Using the getFileName method in the PATH class, the specific: lstrfilename = Lofile.postedFile.FileName 'Note: Lofile.postedFile.FileName Returns the file name selected by the file dialog box, which contains the file's directory information lstrfilename = path .GETFILENAME (LSTRFILENAME) 'Remove directory information, return to file name

(2). Judging whether the upload directory exists, there is no existence

Establish a directory to use the CREATEDIRECTORY method in the Directory class, and determine if the directory exists in the Directory class. details as follows:

IF (not Directory.exists (LstrfileFolder) "" LstrfileFolder) end if 'Note: lstrfilefolder is the name of the directory that the user is filled in, or the default directory name

. Upload selected files to the server

After the previous work has been completed, you can upload the file, the upload file is relatively simple, use the following 2 line statement to complete the upload work.

LstrfileNamePath = lstrfilefolder & lstrfilename 'get upload directory and file name lofile.postedfile.saveas (lstrfilenamepath)' upload file to server

<5>. Get and display the properties of the upload file

FileName.Text = lstrFileName 'get file name FileType.Text = loFile.PostedFile.ContentType' file type obtained FileLength.Text = cStr (loFile.PostedFile.ContentLength) 'get file length FileUploadForm.visible = false AnswerMsg.visible = true' Show Upload file properties is above some of the more important places when writing.

You can determine the file type uploaded by the user in the program: ---------------------- 'get file type fileType.text = Lofile.postedFile.contentType - -------------------- then decide whether it is accepting or refused.

转载请注明原文地址:https://www.9cbs.com/read-10772.html

New Post(0)