Asp. NET Knowledge Summary (5. File upload 6. File download)

Source: Internet
Author: User

5. File Upload

-"NOTE: Using the HTTP protocol is only suitable for transferring small files, if you want to pass large files, you need to use plug-in or client program (using FTP protocol)

-"Client action"

"1"adds attributes to the form:enctype= "Multipart/form-data"

"2"adding Controls to the form:<input type= "file" name= "F1"/>

"3" form must use post submission method

-"server-side operations"

"1" using the request.files property to get the file object

2Savewith the SaveAs () method of the httppostedfile Object

-"Observe the data message

When you set the enctype= "Multipart/form-data" property of a form, it is no longer the key-value format, but instead uses the delimiter in the request body

-"limit: Upload executable file is not allowed, only allow static file upload

Example: Only upload images are allowed

Client-side Checksum

Server-side Check

-"Improve: Save the file to the corresponding year, month, and Day folder for easy traversal

Dynamically creating paths

Stitching path Information

Example:ASPNET Project Review / /t1_upload_downloadof the next day

6. File Download

-"Use hyperlinks to directly specify the files to download

Text that can be parsed by the browser will be displayed

Files that cannot be parsed by the browser will be downloaded

-"Implementation: No matter the file format, do not use the browser display, complete the download

Point to generic handler, file address as parameter

Modify the response header:ContentType = "Application/octet-stream";

Set header information:addheader ("content-disposition", "attachment; Filename=\ " file name \"; ");

Output file:context. Response.WriteFile ( file address );

-"Hint: If the Chinese file name is garbled, URL encoding can be

Httputility.urlencode (filename, System.Text.Encoding.UTF8);

Returns a string as the name of the file

Example:ASPNET Project Review / /t1_upload_downloadof the next day

Asp. NET Knowledge Summary (5. File upload 6. File download)

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.