Partilhar via


How to: Create Resource Files for ASP.NET Web Sites

A resource file is an XML file that contains the strings that you want to translate into different languages. You create a separate resource file for each language that you want to translate a Web page into.

Global resource files are available to any page or component in the Web site. Local resource files are associated with a single Web page and contain the translated text for that page only. For more information, see ASP.NET Web Page Resources Overview.

Visual Studio 2005 includes an editor for managing resources that simplifies the process of creating resource files. For more information, see How to: Create Resource Files for ASP.NET Web Sites (Visual Studio) and How to: Create Resource Files for ASP.NET Web Sites and How to: Create Resource Files for ASP.NET Web Sites.

To create a resource file for an ASP.NET Web site

  1. Create a new text file that has the extension .txt.

  2. In the text file, create key/value pairs using the format key=value. Keys are not case sensitive.

    The following code example shows two key/value pairs:

    Button1Text=Submit
    Label1Text=Welcome!
    
  3. Save the file.

  4. In Microsoft Windows, open a Command Prompt window, and then go to the folder that contains the command-line utilities for the .NET Framework version 2.0. The path is as follows:

    %windows%\Microsoft.NET\Framework\version\sdk\bin
    

    For version, substitute the name of the folder for the .NET Framework version that you are currently using.

  5. Run the Resgen utility, using the following syntax:

    resgen textfile.txt resourcefile.resx
    

    For example, if in step 1 you created a file named SiteResources.txt, the command might look similar to the following:

    resgen c:\WebSite\SiteResources.txt c:\WebSite\SiteResources.resx
    

    You can include a full path, when specifying the names of the text and resource files.

    When the command runs, it creates a .resx file that includes the correct XML definitions and elements.

  6. Copy the resource file to the appropriate location in the Web site:

    • To use the resource file as a global resource, copy it to App_GlobalResources.

    • To use the resource file as a local resource, copy it to App_LocalResources.

  7. Create additional resource files for each language or language and culture (CultureInfo name) that you want to support in your application. You can do either of the following:

    • Copy the first resource file to a new name that includes the language or language and culture information, and then translate the contents of the value elements to another language.

    • Repeat Steps 1 through 5 with the same key/value pairs, but with the values translated to another language. For the file name in step 5, include the language or language and culture names.

    For example, the Spanish version of the SiteResources.resx file would be SiteResources.es.resx.

    NoteNote

    When naming resource files, do not include .aspx in the name, because this can result in a naming conflict. For example, the Resource folder cannot contain two files with names such as resTestPage.resx and resTestPage.aspx.resx because the resolution of the file names at compile-time would create a naming conflict, resulting in a compile-time error.

See Also

Other Resources

Localizing ASP.NET Web Pages Using Resources