This documentation is archived and is not being maintained.

ResourceWriter.AddResource Method (String, Stream)

Updated: May 2012

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

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

public void AddResource(
	string name,
	Stream value


Type: System.String
The name of the resource to add.
Type: System.IO.Stream
The value of the resource to add. The resource must support the Stream.Length property.


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


The stream does not support the Length property.


name or value is null.


This ResourceWriter has been closed.

You can specify any stream that supports the Length property for value.

You can retrieve the resources written by the AddResource method by calling the ResourceManager.GetStream method.

The following example uses the AddResource method to add a graphics image that has been saved to a MemoryStream object to a ResourceWriter object.

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Resources;

public class Example
   public static void Main()
      // Bitmap as stream
      MemoryStream bitmapStream = new MemoryStream();
      Bitmap bmp = new Bitmap(@".\\AppImage.jpg");
      bmp.Save(bitmapStream, ImageFormat.Jpeg);

      using (ResourceWriter rw = new ResourceWriter(@".\UIImages.resources"))
         rw.AddResource("Bitmap", bitmapStream);
         // Add other resources.

.NET Framework

Supported in: 4

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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




May 2012

Revised extensively.

Information enhancement.