Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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.115.6K
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
Rate this: bad
good
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.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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 BillWoodruff 360
1 Mathew Soji 309
2 DamithSL 225
3 Afzaal Ahmad Zeeshan 202
4 Maciej Los 190
0 OriginalGriff 6,249
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 3,865


Advertise | Privacy | Mobile
Web04 | 2.8.1411019.1 | Last Updated 8 May 2013
Copyright © CodeProject, 1999-2014
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