ASP. NET Single File Upload using controls
<Asp: FileUpload ID = "upmess" runat = "server" Width = "248px"/>
Background code
Try {
If (upmess. HasFile = true) // you can determine whether a file has been uploaded.
{
Bool fileOk = false;
String fileExtension = System. IO. Path. GetExtension (upmess. FileName). ToLower ();
String [] allowExtension = {". doc ",". txt ",". wps ",". xls ",". zip ",". pdf ",". rar "}; // File Upload type restrictions
For (int I = 0; I <allowExtension. Length; I ++)
{
If (fileExtension = allowExtension [I])
{
FileOk = true;
Break;
}
}
If (fileOk)
{
Int filesize = upmess. PostedFile. ContentLength;
If (filesize <15360000)/* size limit of the uploaded file */
{
String path = Server. MapPath ("~ ");
Random r = new Random ();
R. Next (1,100 );
String mark = r. Next (1, 1000). ToString ();
Filename = "[" + mark + "]" + upmess. FileName;
Upmess. PostedFile. SaveAs (path + "\ view \" + filedizi + "\" + filename); // Save the uploaded file to the specified directory
}
When obtaining uploaded files
Response. Redirect (@ "" + path + "/" + filename );
The size and time of the file to be uploaded. You can configure the number of files simultaneously uploaded by multiple users in webConfig.
<System. web>
<HttpRuntime executionTimeout = "600" maxRequestLength = "15360000" // file size limit
UseFullyQualifiedRedirectUrl = "false" minFreeThreads = "8"
MinLocalRequestFreeThreads = "4" // number of files simultaneously uploaded by multiple users: 4-8
AppRequestQueueLimit = "100" // the response time is 100 ms.
EnableVersionHeader = "true"/>
<HttpHandlers>