简体   繁体   English

为什么我收到错误找不到其他文件夹中的文件名而不是我给的那个?

[英]Why I'm getting error can't find file name in other folder then the one I gave?

private void GetMessages()
{
    DirectoryInfo d = new DirectoryInfo(@"D:\Csharp Projects\Get Messages\Sources");//Assuming Test is your Folder
    FileInfo[] Files = d.GetFiles("*.html"); //Getting Text files

    foreach (FileInfo file in Files)
    {
        using(StreamReader reader = new StreamReader(file.Name))
        {
            string line;

            while((line = reader.ReadLine()) != null)
            {
                if(line.Contains("msg-bullet"))
                {
                    int index = line.IndexOf("<");
                    int index1 = line.IndexOf(">");

                    string result = line.Substring(index, 4);
                }
            }
        }
    }
}

I'm getting the error on the line:我在线收到错误消息:

using(StreamReader reader = new StreamReader(file.Name))

Could not find file 'D:\Csharp Projects\Get Messages\bin\Debug\Source0.html找不到文件 'D:\Csharp Projects\Get Messages\bin\Debug\Source0.html

The path from the error message D:\Csharp Projects\Get Messages\bin\Debug isn't the path or even a subpath from the one I provided in the source, eg D:\Csharp Projects\Get Messages\Sources错误消息D:\Csharp Projects\Get Messages\bin\Debug的路径不是我在源代码中提供的路径甚至是子路径,例如D:\Csharp Projects\Get Messages\Sources

Why isn't the given path used?为什么不使用给定的路径?

Solution is to use file.FullName:解决方案是使用 file.FullName:

using (StreamReader reader = new StreamReader(file.FullName))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我收到此错误? - Why I'm getting this error? 有人可以解释为什么我为此得到一个模棱两可的调用错误吗? - Can someone explain why I'm getting an ambiguous invocation error for this? 错误:“; 预期”,找不到我想念的地方 - Error: “; expected”, can't find where I'm missing it 在操纵Windows文件系统中,将文件从一个目录移动到另一个目录时出现异常 - In Manipulating the Windows file system I'm getting an exception while moving file from one directory to other 为什么我不能通过商店名称和哈希找到证书? - Why can't I find the certificate by store name and hash? 我可以将文件从一个项目文件夹发送到C#Web中的另一个项目文件夹吗 - Can I send file from one project folder to an other project folder in C# web 我想将文件复制到另一台服务器,但是出现“找不到路径的一部分”错误 - I want to copy a file to another server, but I'm getting a “could not find part of path” error Mono有没有任何模拟框架?我很遗憾,我似乎无法找到一个 - Are there any mocking frameworks for Mono??? I'm floored that I can't seem to find one 我正在尝试使用dll文件名:CDSDK.dll,但出现错误,此错误是什么? - I'm trying to use a dll file name: CDSDK.dll but getting an error what is this error? 我收到类型初始值设定项异常,无法找出问题所在 - I'm getting type initializer exception and can't find out what's wrong
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM