There is no such thing as ".dat file", more exactly, it can be anything. Accordingly, it can be created in a number of way. The question per se makes little to no sense.
You should understand that file names do not matter much, even though some conventions on the name pattern exist and "file types" are registered in the system registry and associated with certain application to handle them. There is no other meaning associated to file name patterns.
To work with files in .NET, use