如何在C#中1个1个地加载目录中的文件?
我想使用 C# 1 1 加载所有 xml 文件。并且所有文件都位于同一目录下。 你能给我一些样品吗?
谢谢 苏特
I want to load all xml files 1 by 1 by using C#. And all files are under same directory.
Could you please give me some samples for it?
Thanks
SuT
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需凭记忆输入此内容,但我相信这会起作用:
如果您确实需要进入子文件夹,请进行以下更改:
Just typing this from memory, but this would do the trick I believe:
If you do need to go into child folders then make this change:
我不确定你所说的“1 by 1”是什么意思,但我想这就是你正在寻找的。
xmls
是myPath
中的所有文件,也是所有子文件夹中的文件,通过 SearchOption 您可以定义是否需要所有文件或仅顶级文件。接下来,对每个找到的文件打开一个文件流,并使用流读取器来读取整个内容。i'm not sure what you mean with "1 by 1" but i guess this is what you are looking for.
xmls
are all files inmyPath
and also inside all subfolders via SearchOption you can define if you want all files or only TopLevel files. Next a fileStream is openend for eaech of the found files and a stream reader is used to read the whole content.