This documentation is archived and is not being maintained.

ResXResourceReader Class

Enumerates XML resource (.resx) files and streams, and reads the sequential resource name and value pairs.

Namespace: System.Resources
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public class ResXResourceReader : IResourceReader, IEnumerable, IDisposable
public class ResXResourceReader implements IResourceReader, IEnumerable, 
	IDisposable
public class ResXResourceReader implements IResourceReader, IEnumerable, 
	IDisposable
Not applicable.

The ResXResourceReader provides a default implementation of the IResourceReader interface that reads resource information in an XML format. To read resource information from a binary resource format, use ResourceReader.

You can use resource readers to read resource name and value pairs from .resx files. The resources can be enumerated by traversing the IDictionaryEnumerator returned by the GetEnumerator method. You can use the methods provided by the IDictionaryEnumerator to advance to the next resource and read the name and value of each resource in the .resx file.

For more information on the format of a .resx file, see Resources in .Resx File Format.

NoteNote:

IEnumerable.GetEnumerator returns an IEnumerator not IDictionaryEnumerator.

NoteNote:

This class contains a link demand and an inheritance demand at the class level that applies to all members. A SecurityException is thrown when either the immediate caller or the derived class does not have full-trust permission. For details about security demands, see Link Demands and Inheritance Demands.

The following example demonstrates how to use a ResXResourceReader to iterate through the resources in a .resx file. First, the ResXResourceReaderrsxr is created for the file items.resx. Next, the GetEnumerator method is used to create an IDictionaryEnumerator to iterate through the resources and display the contents to the console.

using System;
using System.Resources;
using System.Collections;

class ReadResXResources
{
   public static void Main()
   {
   
      // Create a ResXResourceReader for the file items.resx.
      ResXResourceReader rsxr = new ResXResourceReader("items.resx");

      // Create an IDictionaryEnumerator to iterate through the resources.
      IDictionaryEnumerator id = rsxr.GetEnumerator();       

      // Iterate through the resources and display the contents to the console.
      foreach (DictionaryEntry d in rsxr) 
      {
	Console.WriteLine(d.Key.ToString() + ":\t" + d.Value.ToString());
      }

     //Close the reader.
     rsxr.Close();
   }
}

  • SecurityAction.LinkDemand  for full trust for the immediate caller. This member cannot be used by partially trusted code.
  • SecurityAction.InheritanceDemand  for full trust for inheritors. This class cannot be inherited by partially trusted code.

System.Object
  System.Resources.ResXResourceReader

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 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

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