Click here to Skip to main content
11,496,146 members (466 online)
The site is currently in read-only mode for maintenance. Posting of new items will be available again shortly.
See more: ASP.NET
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;
    GridView1.DataBind();
}
Posted 8-May-13 1:16am
Edited 8-May-13 2:41am
Johnny J.126.2K
v5
Comments
Tadit Dash at 8-May-13 6:55am
   
What are you using for file upload control input type="file" or asp:FileUpload ?
Member 7909184 at 8-May-13 6:58am
   
i'm using input type="file"
Member 7909184 at 8-May-13 7:12am
   
thanxxxxxxxxxxxxxx
Tadit Dash at 9-May-13 1:21am
   
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.
  Permalink  
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...

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 10,401
1 OriginalGriff 8,910
2 Sascha Lefèvre 3,899
3 Maciej Los 3,422
4 Richard Deeming 2,600


Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 8 May 2013
Copyright © CodeProject, 1999-2015
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