Solved

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

Posted on 2012-04-10
3
154 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

739 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