Home > Software engineering >  File.Exists() throws an error in my Visual Studio 2022 / ASP.NET Core 6 MVC project
File.Exists() throws an error in my Visual Studio 2022 / ASP.NET Core 6 MVC project

Time:06-22

I am trying to use File.Exists(Path), but I keep getting this "Compiler Error CS0119". I was looking into if I needed a special using statement.

I can't figure out why it is not working. I originally was trying to learn how to use it. The docs and all the answers when trying to check to see if a file existed basically lead to this answer, but when I try using it I get this weird error. If it is that I simply need to restart my computer because of this issue I will let you know.

I am using it correctly but I don't know what the actual issue is. Additionally, I actually used a string like File.Exista("thisString") to see if that would make a difference but it did not.

UPDATE

Even with the using statements using System; using System.IO, I still had to use System.IO.File.Exists(Path) I did not know that and I hope this helps many people out. I say that because this is an issue with the IDE or something for now allowing me to use just the using statement. Thank you @Elliveny

enter image description here

CodePudding user response:

You have to use

System.IO.File.Exists(filePath)

since ControllerBase does also contain a definition of File. And since you have both using statements, it is unclear which File. you want to use.

  • Related