I have written code in C# and printed results to the terminal to confirm it is working. I am currently in the process of transferring some of the code over to an MVC 4 Controller and I have been able to successively merge most of it but I am having issues with one part.
I wish to read a database file (database.dat) and later on I wish to write to the same file.
In my controller I have:
using (FileStream stream = File.OpenRead("database.dat")) database = (List)formatter.Deserialize(stream);
and
using (Stream stream = File.Open("database.dat", FileMode.Create)) formatter.Serialize(stream, database);
In both cases 'File' in File.OpenRead and File.Open is underlined and I receive the error:
'System.Web.Mvc.Controller.File(byte[], string)' is a 'method', which is not valid in the given context ..."
Is there way I can achieve the same result in MVC?
C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...
In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.
What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.
C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.
You'll have to add the fully-qualified name if you want to use the File
class in System.IO
(http://msdn.microsoft.com/en-us/library/system.io.file.aspx). So something like this should work:
using (FileStream stream = System.IO.File.OpenRead("database.dat")){
database = (List)formatter.Deserialize(stream);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With