Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将文件夹中存储的文件列表检索到我的解决方案ASP.NET中_C#_Asp.net_Pdf_Tabular - Fatal编程技术网

C# 将文件夹中存储的文件列表检索到我的解决方案ASP.NET中

C# 将文件夹中存储的文件列表检索到我的解决方案ASP.NET中,c#,asp.net,pdf,tabular,C#,Asp.net,Pdf,Tabular,我不确定我是否在正确的位置问这个问题,我正在尝试创建一个表,将文件夹中的所有PDF文件放入我的解决方案中 我试图检索它们的名字,并将它们放在一个表中,以便在整个链接中访问它们 我得到了下面的方法,但是,它不起作用 protected void ListFiles() { const string MY_DIRECTORY = @"~/HistoricalFiles"; string strFile = null; foreach (str

我不确定我是否在正确的位置问这个问题,我正在尝试创建一个表,将文件夹中的所有PDF文件放入我的解决方案中

我试图检索它们的名字,并将它们放在一个表中,以便在整个链接中访问它们

我得到了下面的方法,但是,它不起作用

protected void ListFiles()
    {
        const string MY_DIRECTORY = @"~/HistoricalFiles";
        string strFile = null;
        foreach (string s in Directory.GetFiles(Server.MapPath(MY_DIRECTORY), "*.*"))
        {
            strFile = s.Substring(s.LastIndexOf("\\") + 1);
            //ListBox1.Items.Add(strFile);
        }
    }

有什么方法可以让我轻松地访问所有文件夹并以良好的方式显示它们吗?

通过查看您的图像,您应该更改文件夹的路径。它不在根目录中,它在
Reports\API
文件夹中

const string MY_DIRECTORY = @"~/Reports/API/HistoricalFiles";

“不工作”是什么意思?它是否抛出异常?找不到任何文件?我的意思是,该方法找不到目录。您不能调试并获取Server.MapPath(MY_目录)的值吗?验证文件夹是否是您期望的文件夹,以及它是否确实存在