Link to home
Start Free TrialLog in
Avatar of searchsanjaysharma
searchsanjaysharma

asked on

How to read the dirlisting into a array and store in grid.

I have an folder FileRepo: It contains files of the format.
AAAAK5389F1_FORM16A_2010-11_Q1.pdf
AAAAK5389F1_FORM16A_2010-11_Q2.pdf
AAAAK5389F1_FORM16A_2010-11_Q3.pdf
AAAAK5389F1_FORM16A_2010-11_Q4.pdf
AAAAK5389F2_FORM16A_2010-11_Q1.pdf
AAAAK5389F2_FORM16A_2010-11_Q2.pdf
AAAAK5389F2_FORM16A_2010-11_Q3.pdf
AAAAK5389F2_FORM16A_2010-11_Q4.pdf

The user enters the token no. which is common for file.ex. AAAAK5389F1
I want when the user enters this token no. in txttoken
The gridview should be filled with all files containing this token no. i.e
AAAAK5389F1_FORM16A_2010-11_Q1.pdf
AAAAK5389F1_FORM16A_2010-11_Q2.pdf
AAAAK5389F1_FORM16A_2010-11_Q3.pdf
AAAAK5389F1_FORM16A_2010-11_Q4.pdf
ASKER CERTIFIED SOLUTION
Avatar of BuggyCoder
BuggyCoder
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of searchsanjaysharma
searchsanjaysharma

ASKER

Files is the folder where all files are kept.
Its giving System.IO.DirectoryNotFoundException: Could not find a part of the path 'D:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\Files'.

  protected void Button1_Click(object sender, EventArgs e)
    {
        var dt = new DataTable();
        dt.Columns.Add("Name", typeof(string));

        Directory.GetFiles("Files",TextBox1.Text.Trim()+"*.pdf")
            .ToList()
            .ForEach(s =>
            {
                var dr = dt.NewRow();
                dr.SetField<string>("Name", s.Substring(s.LastIndexOf('\\') + 1));

                dt.Rows.Add(dr);
            });

        if (dt.Rows.Count > 0)
        {
            GridView1.DataSource = dt;
            GridView1.DataBind();
        }

    }