This documentation is archived and is not being maintained.

ResourceReader.ResourceReader(String) Constructor

Initializes a new instance of the ResourceReader class for the specified resource file.

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

public ResourceReader (
	string fileName
)
public ResourceReader (
	String fileName
)
public function ResourceReader (
	fileName : String
)
Not applicable.

Parameters

fileName

The path of the resource file to be read.

Exception typeCondition

ArgumentNullException

The fileName parameter is a null reference (Nothing in Visual Basic).

FileNotFoundException

The file cannot be found.

IOException

An I/O error has occured.

BadImageFormatException

The resource file has an invalid format. For example, the length of the file is zero.

The following code example defines a new instance of the ResourceReader class that will read from the specified file. The code then retrieves an enumerator, iterates through the file, and prints key/value pairs to the console.

using System;
using System.Resources;
using System.Collections;
 
public class ReadResources {

   public static void Main(string[] args) {

      // Opens a resource reader and gets an enumerator from it.
      IResourceReader reader = new ResourceReader("myResources.resources");
      IDictionaryEnumerator en = reader.GetEnumerator();
      
      // Goes through the enumerator, printing out the key and value pairs.
      while (en.MoveNext()) {
         Console.WriteLine();
         Console.WriteLine("Name: {0}", en.Key);
         Console.WriteLine("Value: {0}", en.Value);
      }
      reader.Close();
   }
}

import System.*;
import System.Resources.*;
import System.Collections.*;

public class ReadResources
{
    public static void main(String[] args)
    {
        // Opens a resource reader and gets an enumerator from it.
        IResourceReader reader = new ResourceReader("myResources.resources");
        IDictionaryEnumerator en = reader.GetEnumerator();

        // Goes through the enumerator, printing out the key and value pairs.
        while(en.MoveNext()) {
            Console.WriteLine();
            Console.WriteLine("Name: {0}", en.get_Key());
            Console.WriteLine("Value: {0}", en.get_Value());
        }
        reader.Close();
    } //main
} //ReadResources

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, 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

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0
Show: