Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Using this code I'm uploading the file and showing on gridview. But when I click the upload button nothing happen and no error come....

I have checked by debugging when I select the file nothing comes to the object of HttpFileCollection means hfc gives null.

Please help me

C#
protected void btnUpload_Click(object sender, EventArgs e)
{
    HttpFileCollection hfc = Request.Files; // htc gives null
    foreach (string filetagname in hfc)
    {
        HttpPostedFile hpf = Request.Files[filetagname];
        if (hpf.ContentLength > 0)
        {
            int size = hpf.ContentLength;
            string name = hpf.FileName;
            int position = name.LastIndexOf(@"\\");
            name = name.Substring(position + 1);
            string content = hpf.ContentType;
            byte[] filedata = new byte[size];
            hpf.InputStream.Read(filedata, 0, size);
            filedownload.savefile(name, content, size, filedata);

        }
    }

    DataTable dt = filedownload.GetFileList();
    GridView1.DataSource = dt;
    GridView1.DataBind();
}
Posted
Updated 8-May-13 1:41am
v5
Comments
What are you using for file upload control input type="file" or asp:FileUpload ?
fak_farrukh 8-May-13 6:58am    
i'm using input type="file"
fak_farrukh 8-May-13 7:12am    
thanxxxxxxxxxxxxxx
Welcome...

Follow my answer. Please accept and upvote.

Thanks,
Tadit

Hey see HttpRequest.Files Property[^]
It shows a good example of using this functionality, Hope this helps.
 
Share this answer
 
v2
Follow the answer Upload more than one file aspx.net C#[^].
Quote:

As far as I can see, you just need to add enctype="multipart/form-data" to your form:

You are not using asp:FileUpload control which adds that enctype automatically, so you should do that manually.

Thanks...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900