Click here to Skip to main content
15,068,581 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to display the uploaded file(any) data into gridview using asp.net with vb.net how can i do this please help me
Posted
Comments
Ankur\m/ 12-Feb-11 2:23am
   
What have you tried? Have you even searched Google for examples?

1 solution

Hi Once the form posted, you can access the uploaded files details though the file upload control's properties
1) Add a gridview, button, file upload control and a object datasource.
2) Create two classes as shown below
C#
public class FileDetail
{
    public string Name { get; set; }
    public string Type { get; set; }
    public int Length { get; set; }
}

C#
public static class FileDetailCollection
{
    public static IList<FileDetail> FileList =new List<FileDetail>();
    public static IList<FileDetail> GetAll()
    {
        return FileList;
    }
}

3) Configure the objectdatasource with the FileCollection object and the select method as GetAll
4)Set Gridview's (in my examble gridview4) datasource to the object data source created
5) In the button's click event (form submission) have the following code
C#
HttpPostedFile postedFile= FileUpload1.PostedFile;
FileDetail fDetail = new FileDetail();
fDetail.Length = postedFile.ContentLength;
fDetail.Name = postedFile.FileName;
fDetail.Type = postedFile.ContentType;
FileDetailCollection.FileList.Add(fDetail);
GridView4.DataBind();
   
v2
Comments
Sandeep Mewara 12-Feb-11 4:39am
   
Good answer. 5!

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