Home
Manage Your Code
Snippet: Write binary file (C#)
Title: Write binary file Language: C#
Description: Write a binary file - taken from http://www.bytemycode.com/snippets/snippet/359/ Views: 439
Author: Nick Lucent Date Added: 12/18/2006
Copy Code  
1/// <summary>

2/// Write a binary file

3/// </summary>

4/// <param name="filePath">Full path of file to be written</param>

5/// <returns>True, if success</returns>

6public bool WriteBinaryFile(string filePath, byte[] contents)
7{
8        bool okok = true;
9
10        try
11        {
12                using (FileStream fs = new FileStream(filePath, FileMode.CreateNew))
13                {
14                    using (BinaryWriter w = new BinaryWriter(fs))
15                    {
16                        w.Write(contents);
17                    }
18                }
19        }
20        catch (IOException e)
21        {
22                okok = false;
23        }
24
25        return okok;
26}