Aymen Kareem Aymen Kareem - 6 months ago 39
C# Question

How Can I Use File class in an MVC Controller in ASP.Net?

I have a little problem here. I'm using the following statement in a controller in ASP.NET MVC:

using (var fileStream = File.Create(path))

I get the following error:

'Controller.File(byte[], string)' is a method, which is not valid in the given context

It seems that there's a function named File in the parent Controller class that my controller inherits from.

How can I tell the compiler that File here is a class not a function?


You can use the full namespace to explicitly point at the correct File class:

using (var fileStream = System.IO.File.Create(path))