Export (0) Print
Expand All

ResourceWriter.AddResource Method (String, Byte[])

Adds a named resource specified as a byte array to the list of resources to be written.

Namespace:  System.Resources
Assembly:  mscorlib (in mscorlib.dll)

public void AddResource(
	string name,
	byte[] value


Type: System.String

The name of the resource.

Type: System.Byte[]

Value of the resource as an 8-bit unsigned integer array.


IResourceWriter.AddResource(String, Byte[])


name (or a name that varies only by capitalization) has already been added to this ResourceWriter.


The name parameter is null.


This ResourceWriter has been closed and its hash table is unavailable.

The resource is not written until Generate is called.

You can retrieve the resources written by the AddResource(String, Byte[]) method by calling the ResourceManager.GetStream method.

The following example uses the AddResource(String, Byte[]) method to add a graphics image that has been read as an array of bytes to a ResourceWriter object.

using System;
using System.IO;
using System.Resources;

public class Example
   public static void Main()
      // Get the image as an array of bytes.
      FileStream byteStream = new FileStream("AppIcon.jpg", FileMode.Open);
      Byte[] bytes = new Byte[(int) byteStream.Length];
      byteStream.Read(bytes, 0, (int) byteStream.Length);

      // Create the resource file. 
      using (ResourceWriter rw = new ResourceWriter(@".\UIImages.resources")) {
         rw.AddResource("AppIcon", byteStream);
         // Add any other resources.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft