C # file upload,

Source: Internet
Author: User
Tags ftp protocol

C # file upload,
I. Analysis

This blog mainly solves a series of problems such as file upload, which will be discussed in two aspects: files within 1 GB and files above 1 GB.

You can use the following three upload methods to upload files within 1 GB: use the Web Control FileUpload, html control HtmlInputFile, and Html element <input type = "file" id = "file"/> to Request. files upload.

For large files larger than 1 GB, the idea is:

(1) Protocol: http or ftp protocol can be used

(2) resumable upload

(3) Use plug-ins

(4) non-plug-in implementation

2. The file size is in the range of [0, 1G]

Upload the html control HtmlInputFile:

1. upload interface

2. Front-end code

<% @ Page Language = "C #" AutoEventWireup = "true" CodeBehind = "myInputFile. aspx. cs" Inherits = "FileUpLoad. WebForm2" %> <! DOCTYPE html> 

3. backend code

Protected void btnUpLoad_Click (object sender, EventArgs e) {// string serverpath = Server. MapPath ("~ /ImageFile "); if (file1.PostedFile. contentLength> 0) {if (File. exists (@ "C: \ Users \ WJM \ Desktop \ FilesUpLoad \" + file1.PostedFile. fileName) {Label1.Text = "the file already exists";} else {file1.PostedFile. saveAs (@ "C: \ Users \ WJM \ Desktop \ FilesUpLoad \" + file1.PostedFile. fileName); Label1.Text = "Upload successful! ";}} Else {Label1.Text =" Upload Failed ";}}

4. Configuration File

<? Xml version = "1.0" encoding = "UTF-8"?> <! -- For more information about how to configure ASP. NET applications, visit the http://go.microsoft.com/fwlink? LinkId = 169433 --> <configuration> <system. web> 

Note: If you are not familiar with configuration files, refer to my other blog: ASP. NET Web. config.

Web Control FileUpload implementation

1. upload interface

3. The file size is within the range of [1G, 10G]

 

Note: It is not complete. Please wait .......

  • Thank you for your reading. If you have any shortcomings, please kindly advise and learn and make progress together.
  • Blog website: http://www.cnblogs.com/wangjiming /.
  • This blog is original to bloggers.
  • If you like, please recommend it; if you have new ideas, welcome to raise, mailbox: 2016177728@qq.com.
  • This blog can be reposted, but it must be a famous blog source.

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.