Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 357
  • Last Modified:

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

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
searchsanjaysharma
Asked:
searchsanjaysharma
1 Solution
 
Meir RivkinFull stack Software EngineerCommented:
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
 
searchsanjaysharmaAuthor Commented:
ok
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now