Solved

How to pick only aaaa*.pdf file in GetFiles() function, and how to add to Gridview.

Posted on 2012-04-10
2
348 Views
Last Modified: 2012-06-27
The following code displays all the file names.
1.How to pick the files name having the format as xxxxx_yyyy.pdf
here the xxxxx is being entered from Textbox t1.
2.What ever the resultset comes should be added to Gridview1.

DirectoryInfo dir = new DirectoryInfo(MapPath("Files/"));
        FileInfo[] files = dir.GetFiles();
        ArrayList listItems = new ArrayList();
        foreach (FileInfo info in files)
        {
            listItems.Add(info);
            Response.Write(info.ToString());
        }
0
Comment
Question by:searchsanjaysharma
2 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 37831238
FileInfo[] files = dir.GetFiles(string.Format("{0}_yyyy.pdf", t1.Text));

if you don't care about characters after the underscore then use:

FileInfo[] files = dir.GetFiles(string.Format("{0}_*.pdf", t1.Text));
0
 

Author Closing Comment

by:searchsanjaysharma
ID: 37831248
ok
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

895 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

11 Experts available now in Live!

Get 1:1 Help Now