Solved

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

Posted on 2012-04-10
2
347 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
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!
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 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

13 Experts available now in Live!

Get 1:1 Help Now