Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

ResourceReader Constructor (String)

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

Namespace:  System.Resources
Assembly:  mscorlib (in mscorlib.dll)
public ResourceReader(
	string fileName


Type: System.String

The path and name of the resource file to read. filename is not case-sensitive.


The fileName parameter is null.


The file cannot be found.


An I/O error has occurred.


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

The ResourceReader(String) constructor instantiates a ResourceReader object that retrieves resources from a standalone .resources file. To retrieve resources from an embedded .resources file, use the ResourceReader(Stream) constructor.

Security noteSecurity Note

Using an instance of this object with untrusted data is a security risk. Use this object only with trusted data. For more information, see Untrusted Data Security Risks.

The example in this section uses the following .txt file named PatientForm.txt to define the resources used by an application.

Title="Top Pet Animal Clinic"
Label1="Patient Number:"
Label2="Pet Name:"
Label5="Date of Birth:"
Label9="Home Phone:"
Label10="Work Phone:"
Label11="Mobile Phone:"

You can compile this .txt file into a .resources file by issuing the following command:

resgen PatientForm.txt

The following example enumerates the resources in PatientForm.resources and displays the name and value of each.

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

public class Example
   public static void Main()
      var rr = new ResourceReader("PatientForm.resources");
      IDictionaryEnumerator dict = rr.GetEnumerator();
      int ctr = 0;

      while (dict.MoveNext()) {
         Console.WriteLine("{0:00}: {1} = {2}", ctr, dict.Key, dict.Value);

// The example displays the following output: 
//       01: Label3 = "Species:" 
//       02: Label2 = "Pet Name:" 
//       03: Label1 = "Patient Number:" 
//       04: Label7 = "Owner:" 
//       05: Label6 = "Age:" 
//       06: Label5 = "Date of Birth:" 
//       07: Label4 = "Breed:" 
//       08: Label9 = "Home Phone:" 
//       09: Label8 = "Address:" 
//       10: Title = "Top Pet Animal Clinic" 
//       11: Label10 = "Work Phone:" 
//       12: Label11 = "Mobile Phone:"

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft. All rights reserved.