135

I have a byte array (an IEnumerable actually), and I need to save it to a new file containing this data.

How do I do that?

I found some answers telling how to create a MemoryStream from that, but still can't save it to a brand new file.

Daniel Möller
  • 80,567
  • 17
  • 177
  • 200

2 Answers2

345

You can use:

File.WriteAllBytes("Foo.txt", arrBytes); // Requires System.IO

If you have an enumerable and not an array, you can use:

File.WriteAllBytes("Foo.txt", arrBytes.ToArray()); // Requires System.Linq
Mike Christensen
  • 82,887
  • 49
  • 201
  • 310
26

You can use File.WriteAllBytes

Anirudha
  • 31,626
  • 7
  • 66
  • 85