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.

For a list of all members of this type, see ResourceWriter Members.


[Visual Basic]
NotInheritable Public Class ResourceWriter
   Implements IResourceWriter, IDisposable
public sealed class ResourceWriter : IResourceWriter, IDisposable
public __gc __sealed class ResourceWriter : public IResourceWriter,
public class ResourceWriter implements IResourceWriter, IDisposable

Thread Safety

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


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 Generate the file if required.

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


[Visual Basic, C#, C++] The following example writes several strings into the myResources.resources file.

[Visual Basic] 
Imports System
Imports System.Resources

Public Class WriteResources
    Public Shared Sub Main()
        ' Creates a resource writer.
        Dim writer As 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.
    End Sub
End Class

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.

using namespace System;
using namespace System::Resources;

int main() {

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

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

    writer->AddResource(S"String 2", S"Second String");

    writer->AddResource(S"String 3", S"Third String");

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

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Namespace: System.Resources

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: Mscorlib (in Mscorlib.dll)

See Also

ResourceWriter Members | System.Resources Namespace | Developing World-Ready Applications | IResourceWriter | IDisposable