It depends on what level of abstraction you need to work with and what data you work with (text versus binary code).
If you just need to upload the data to a file, you can use the helper methods for File class- WriteAllBytes() for binary (it just writes for FileStream for you) and WriteAllLines() or WriteAllText() for text (using StreamWriter using UTF8NoBOM encoding, unless otherwise specified).
A StreamWriter allows you to write text to a specified stream, which may be a FileStream or some other kind of stream.
If you need to write bytes, and you want to use a low-level control, for example, specify the file mode, system rights, file sharing and other such parameters, you need to work with the file stream. You can also specify these parameters for working with text, passing it to StreamWriter or treating the text as bytes (for example, using the Encoding object).
source share