Edit

Share via


ResourceManager.BaseName Property

Definition

Gets the root name of the resource files that the ResourceManager searches for resources.

public:
 virtual property System::String ^ BaseName { System::String ^ get(); };
public virtual string BaseName { get; }
member this.BaseName : string
Public Overridable ReadOnly Property BaseName As String

Property Value

The root name of the resource files that the ResourceManager searches for resources.

Examples

You can determine the names of embedded .resources files by compiling and running the following utility. This is a console app that accepts the name of a main assembly or satellite assembly as a command-line parameter. It displays the strings that should be provided as the baseName parameter of the ResourceManager(String, Assembly) or ResourceManager(String, Assembly, Type) constructor so that the resource manager can correctly identify the resource.

using System;
using System.IO;
using System.Reflection;
using System.Resources;

public class Example
{
   public static void Main()
   {
      if (Environment.GetCommandLineArgs().Length == 1) { 
         Console.WriteLine("No filename.");
         return;
      }
      
      string filename = Environment.GetCommandLineArgs()[1].Trim();
      // Check whether the file exists.
      if (! File.Exists(filename)) {
         Console.WriteLine("{0} does not exist.", filename);
         return;
      }   
      
      // Try to load the assembly.
      Assembly assem = Assembly.LoadFrom(filename);
      Console.WriteLine("File: {0}", filename);
         
      // Enumerate the resource files.
      string[] resNames = assem.GetManifestResourceNames();
      if (resNames.Length == 0)
         Console.WriteLine("   No resources found.");

      foreach (var resName in resNames)
         Console.WriteLine("   Resource: {0}", resName.Replace(".resources", ""));

      Console.WriteLine();
   }
}
Imports System.IO
Imports System.Reflection
Imports System.Resources

Module Example
   Public Sub Main()
      If Environment.GetCommandLineArgs.Length = 1 Then 
         Console.WriteLine("No filename.")
         Exit Sub
      End If
      Dim filename As String = Environment.GetCommandLineArgs(1).Trim()
      ' Check whether the file exists.
      If Not File.Exists(filename) Then
         Console.WriteLine("{0} does not exist.", filename)
         Exit Sub
      End If   
      
      ' Try to load the assembly.
      Dim assem As Assembly = Assembly.LoadFrom(filename)
      Console.WriteLine("File: {0}", filename)
         
      ' Enumerate the resource files.
      Dim resNames() As String = assem.GetManifestResourceNames()
      If resNames.Length = 0 Then
         Console.WriteLine("   No resources found.")
      End If
      For Each resName In resNames
         Console.WriteLine("   Resource: {0}", resName.Replace(".resources", ""))
      Next
      Console.WriteLine()
   End Sub
End Module

Remarks

The BaseName property reflects the fully qualified namespace name and the root resource name of a resource file, without its culture or file name extension. For example, if an app's default resource file is named SampleApps.StringResources.resources, the value of the BaseName property is "SampleApps.StringResources". If an app's default resource file is named SampleApps.StringResources.en-US.resources and is embedded in a satellite assembly, the value of the BaseName property is still "SampleApps.StringResources".

Important

The BaseName property value of a resource file that is compiled and embedded from the command line does not include a namespace name unless you explicitly include one when compiling the file. On the other hand, the BaseName property value of a resource file that is compiled and embedded within the Visual Studio environment typically does include the default namespace name.

The BaseName property value is the same as the string passed to the ResourceManager(String, Assembly) or ResourceManager(String, Assembly, Type) constructor when instantiating a ResourceManager instance.

Applies to