Click here to Skip to main content
13,150,385 members (30,139 online)
Rate this:
Please Sign up or sign in to vote.
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

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;
Posted 8-May-13 0:16am
Updated 8-May-13 1:41am
Johnny J.168.3K
Tadit Dash 8-May-13 6:55am
What are you using for file upload control input type="file" or asp:FileUpload ?
Member 7909184 8-May-13 6:58am
i'm using input type="file"
Member 7909184 8-May-13 7:12am
Tadit Dash 9-May-13 1:21am

Follow my answer. Please accept and upvote.

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Hey see HttpRequest.Files Property[^]
It shows a good example of using this functionality, Hope this helps.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Follow the answer Upload more than one file C#[^].

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.


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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.170924.2 | Last Updated 8 May 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100