Solved

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

Posted on 2012-04-10
3
158 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 …
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

615 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