Click here to Skip to main content
15,897,315 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
    lstfile.Items.Clear();

            DirectoryInfo dir = new DirectoryInfo(lstfolder.SelectedValue );
            foreach (FileInfo fi in dir.GetFiles())
            {
                lstfile.Items.Add(fi.ToString());
            }
runtime error Could not find a part of the path


What I have tried:

it's a runtime error so not yet do anything
Posted
Updated 13-May-16 21:55pm
Comments
Santosh Kokatnur 14-May-16 1:03am    
What you want to achieve?
Kumbhani Bhavesh 14-May-16 1:40am    
file names

It means you are trying to access the files from a folder which is not present.
Check the values from the lstfolder list and verify physically that the folders are present or not.

in code:

C#
DirectoryInfo dir = new DirectoryInfo(lstfolder.SelectedValue);
          if (dir.Exists)
          {
              foreach (FileInfo fi in dir.GetFiles())
              {
                  lstfile.Items.Add(fi.ToString());
              }
          }

refer: DirectoryInfo.Exists [^]
 
Share this answer
 
What is in "lstfolder"?

If it contains only Directory names, then you have to use,

Server.Mappath(directoyname)


This helps in retrieving entire path of the directory.

Then follow as KARTHIK said.
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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