Asp.net page Upload File control background Code Request. Files cannot be obtained,

Source: Internet
Author: User

Asp.net page Upload File control background Code Request. Files cannot be obtained,

During development today, the page file upload control selects a file, while the value of "Request. Files. Count" in the background is 0. I 've encountered several times in development before. I always forgot about it. I wrote it down today.

Html:

<input type="file" name="file1" >

1. Check whether the label name attribute needs to be added.

2. Add the enctype = "multipart/form-data" attribute to form.

<form id="Form1" method="post" runat="server" enctype="multipart/form-data">

3. Add the MS_POSITIONING = "GridLayout" attribute to the body.

<body MS_POSITIONING="GridLayout">

  

 


Aspnet uploads a file to a general handler and cannot obtain the file.

This is the case if you have a problem.
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "www.w3.org/..al.dtd">

<Html xmlns = "www.w3.org/5o/xhtml">
<Head>
<Title> the html control and ashx are used to save and upload files. </title>
</Head>
<Body>

<! -- Enctype = "multipart/form-data" this type specifies the special data transmission types, such as disks and mp3 files. -->
<Form action = "Handler. ashx" method = "post" enctype = "multipart/form-data" id = "form1">
<P>
<Input id = "imgfile" name = "imgfile" type = "file"/> </p>
<P>
<Input id = "Button1" type = "submit" value = "button"/> </p>
</Form>
</Body>
</Html>

>>>>>>>>>>>>

// The following is the ashx File

<% @ WebHandler Language = "C #" Class = "Handler" %>

Using System;
Using System. Web;

Public class Handler: IHttpHandler {

Public void ProcessRequest (HttpContext context ){
Context. Response. ContentType = "text/plain ";
HttpPostedFile hpf = HttpContext. Current. Request. Files ["imgfile"]; // HttpPostedFile ...... remaining full text>

Why does the aspnet background obtain the value of the foreground html file control ??

You are mistaken. You should use JS to handle the DropDownList change event. When a single change event occurs, the number of <input type = file/> controls is dynamically changed, for example:
$ (Div). remove ($ ('# inputfile _' + $ (# DropDownList). val ()));
Changes to the file upload control do not affect page submission.
At the backend, you only need to process HttpRequest. Files.

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.