Solved

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

Posted on 2012-04-10
3
149 Views
Last Modified: 2012-04-10
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
0
Comment
Question by:searchsanjaysharma
  • 2
3 Comments
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 500 total points
ID: 37829871
            var dt = new DataTable();
            dt.Columns.Add("Name", typeof(string));

            Directory.GetFiles("YourFolderPath", "AAAAK5389F1*.*")
                .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();                
            }

Open in new window

0
 

Author Comment

by:searchsanjaysharma
ID: 37831133
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();
        }

    }
0
 

Author Closing Comment

by:searchsanjaysharma
ID: 37831230
ok
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now