This documentation is archived and is not being maintained.

ResourceWriter Class

Writes resources in the system-default format to an output file or an output stream. This class cannot be inherited.

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

public sealed class ResourceWriter : IResourceWriter, 

ResourceWriter provides a default implementation of the IResourceWriter interface.

Resources are specified as name and value pairs using the AddResource method. Resource names are case-sensitive when used for lookups, but to more easily support authoring tools and help eliminate bugs, ResourceWriter will not allow a .resources file to have names that vary only by case.

To create a resources file, create a ResourceWriter with a unique file name, call AddResource at least once, call Generate to write the resources file to disk, and then call Close to close the file. Calling Close will implicitly call Generate if you do not explicitly call Generate.

The resources will not necessarily be written in the same order they were added.

The following example writes several strings into the myResources.resources file.

using System;
using System.Resources;

public class WriteResources {
   public static void Main(string[] args) {

      // Creates a resource writer.
      IResourceWriter writer = new ResourceWriter("myResources.resources");

      // Adds resources to the resource writer.
      writer.AddResource("String 1", "First String");

      writer.AddResource("String 2", "Second String");

      writer.AddResource("String 3", "Third String");

      // Writes the resources to the file or stream, and closes it.


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0