Click here to Skip to main content
14,774,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I want to know that how I can get a file name from a directory if i don't know which type of file is in directory and what the name of file is.


Please some one help me out
Posted
Updated 8-Nov-10 22:55pm
v2
Comments
Dalek Dave 9-Nov-10 3:55am
   
Edited for Grammar and Syntax.

1 solution

To fetch all the files from directory you need to use Programming language only ASP.NET tag is not enough,

By Assuming you are comfortable with C# I am pasting code here that may help you.

void Page_Load(object s, EventArgs e)
{
 DirectoryInfo di = new DirectoryInfo("c:/inetpub/wwwroot/demos");
 FileInfo[] rgFiles = di.GetFiles("*.aspx");
 foreach(FileInfo fi in rgFiles)
 {
  Response.Write("<br><a href=" + fi.Name + ">" + fi.Name + "</a>");
 }
}



Please vote and Accept Answer if it Helped.
   
Comments
Dalek Dave 9-Nov-10 3:55am
   
Good Answer.
Rajesh Anuhya 9-Nov-10 3:57am
   
Good call

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900