0

I have a TXT file (MyFile.txt) in my shared project which I try to read with File.ReadAllLines()

I tried both File.ReadAllLines("MyFile.txt") and File.ReadAllLines("MyApp\MyFile.txt") and they return:

System.IO.FileNotFoundException: Could not find file

and

System.IO.DirectoryNotFoundException: Could not find a part of the path

respectively.

Which is the correct path?

Costas
  • 459
  • 3
  • 15
  • How are you including a file in your shared project! What is its build action? You typically cannot include files in libraries unless they are embedded resources – Jason Feb 28 '23 at 11:00
  • I am assuming you are using Visual Studio, it could be the case if you are running it as administrator. – user10191234 Feb 28 '23 at 11:01
  • @Jason I have set both no build action and "Resource". No difference. Same errors. – Costas Feb 28 '23 at 11:06
  • @user10191234 Running VS with administrator rights or without makes no difference. – Costas Feb 28 '23 at 11:10
  • A Resource is not a file and does not have a file path. There are numerous existing questions about reading resources in C# – Jason Feb 28 '23 at 11:14
  • I also set it to "Embedded resource". Still getting the same errors. – Costas Feb 28 '23 at 11:16
  • As I noted before, resources are not files and cannot be read using File apis. See the linked question for an example of how to read a resource – Jason Feb 28 '23 at 11:46

0 Answers0