Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2012-04-10
3
Medium Priority
?
162 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

688 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