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
)

Parameters

name
Type: System.String

The name of the resource.

value
Type: System.Byte[]

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

Exception Condition
ArgumentException

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

ArgumentNullException

The name parameter is null.

InvalidOperationException

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
Available since 1.1
Return to top
Show: