How to display all the files from a directory (folder)

Jacklong

New Member
I want to display all of my pictures names in a \[code\]listbox\[/code\]. I'm trying to figure out how to retrieve the file names.I tried this\[code\]protected void Page_Load(object sender, EventArgs e){string u = Request.Url.AbsoluteUri.ToString();string serverPath = u.Substring(0, u.LastIndexOf("/")) + "/UBOimages";Label1.Text = serverPath;DirectoryInfo dirInfo = new DirectoryInfo(Server.MapPath("~/UBOimages"));//FileInfo[] fileInfo = dirInfo.GetFiles();Label2.Text = dirInfo.ToString();}\[/code\]But the results in the labels looks like this:\[code\]http://localhost:49170/UBOimagesC:\Users\John\Documents\UBO\uboWebCustomer\HuronWood\HuronWood\UBOimages\[/code\]and when loaded on the server this page will give an error as it does not like the dirInfo path.What is the correct way to retrieve all the files from a folder (such as the image folder)
 
Back
Top