Aymen Kareem Aymen Kareem - 1 month ago 13
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))
{
stream.CopyTo(fileStream);
}


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?

Answer

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

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