目录无法找到路径的一部分 [英] Directory could not find a part of the path

查看:78
本文介绍了目录无法找到路径的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    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

推荐答案

这意味着你是尝试从不存在的文件夹中访问文件。

检查lstfolder列表中的值并确认文件夹是否存在。



代码:



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:

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



参考: DirectoryInfo.Exists [ ^ ]


lstfolder中的内容是什么? />


如果它只包含目录名,那么你必须使用,



Server.Mappath(directoyname)





这有助于检索目录的整个路径。



然后跟随KARTHIK说。
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.


这篇关于目录无法找到路径的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆