Asp. NET combat File Upload

Source: Internet
Author: User

the more popular cloud disk nowadays,such as Baidu Cloud disk, theCloud Disk,Jinshan Fast plate and so on,I'm sure everyone has used it..Cloud Disk is an Internet storage tool,is the product of Internet cloud technology,is the storage of data information for businesses and individuals over the Internet,services such as reading and downloading,its two largest features are safe and stable and mass storage.my laptop drive is only500G,One day when I found out that my6a hard drive partition is red.4a,I started to go to my Baidu cloud disk"Moving things",This move is what we're going to talk about today."File Upload".


in fact, file upload is very common in Internet applications and web development.,we use in a variety of social software"Photo Upload",when registering online for various exams,uploading photos and so on is essentially a file upload .,but this file is a picture or a photograph ..said so much just to show,file uploads feature a wide range of application areas,so inWebIt's also a very important technology in development ..though I don't know,How to implement the file upload technology of various kinds of network disk,but I believe the general principle is the same..

    recently learning asp.net Technology Use it today to simply simulate the file upload function Not as a commercial development technology use Everybody don't be serious. below to see the specific implementation process :

first create a new ASP Application Project , then add a Web form , The name is self-determined . after it is built as shown :


and then toinputfile.aspxfile for page and design and code writing,What's more important here is aASPControl,calledFileUploadControl.It is mainly called systemAPIto browse the local files,then add the upload.Here we must create a new folder to store files uploaded from the client,For example, I created a new project file under the programUpfilefolders such as


Here's a look at the code section of the foreground and backstage , Given just an example , It's not that complicated for page layouts. , just three controls , first look at the page code

<span style= "FONT-SIZE:18PX;" ><%@ page language= "C #" autoeventwireup= "true" codebehind= "Inputfile.aspx.cs" inherits= "inputfile.inputfile"% ><! DOCTYPE html><link href= "filecss.css" rel= "stylesheet"/>

the corresponding page background code is as follows :

<span style= "FONT-SIZE:18PX;" >  protected void Button1_Click (object sender, EventArgs e)        {            //Gets the absolute path of the file that will be uploaded            string fullfilename = This. FileUpload1.PostedFile.FileName;            The filename of the uploaded file is raised by the string intercept function string            filename = fullfilename.substring (fullfilename.lastindexof ("\ \") + 1);            Use the control's method to save the file to the specified folder in this            . FileUpload1.PostedFile.SaveAs (Server.MapPath ("upfile") + "\ \" + fileName);        } </span>

    Finally we look at the interface of the running result I upload images separately Documents and video files and other files in other formats e.g. zip compressed file, etc.

Of course, during the testing process , , when I upload a - more M the video file when , The error, as far as the larger file, it will not be completed.

Find a way to find a solution on the Internet,Discovery is a control that has a limit on file size,default is4M,How to modify it??it's simple .,only need to be in the configuration fileWeb. configof thesystem.webin thehttpruntimethe following settings can be used in the label:


maxRequestLength indicates the maximum file upload size supported by ASP. This restriction can be used to prevent denial of service attacks that result from the user passing a large number of files to the server. The specified size is in kilobytes. The default value is 4096KB (4 MB).

Executiontimeout indicates the maximum time to allow a request to be executed, in seconds, by default of 90 seconds

Summary: This is a particularly simple example, but it is a particularly useful thing, no matter how superb the technology, is based on these to become more perfect. So it is important to lay a good foundation.

Asp. NET combat File Upload

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.