Export (0) Print
Expand All

Resources in Text File Format

Text (.txt) files can only contain string resources. As long as you save a text file appropriately, you can specify strings using one of three encoding schemes: UTF-16 in either little-endian or big-endian byte order, or UTF-8. For example, if you want to save and use German characters, save your text file using UTF-8 encoding rather than using a specific ANSI code page. For more information on using encodings, see Unicode in the .NET Framework.

Note   The Resource File Generator (Resgen.exe) treats files as UTF-8 by default. For Resgen.exe to recognize a file encoded using UTF-16, you must include a Unicode byte order mark (U+FEFF) at the beginning of the file.

In addition to string entries, text files can contain comments. There is no limit to the number of entries that you can include in a text file. You can also use white space (empty lines) throughout the file to make it easier to read. You should note that surrounding spaces are not included with an individual line when it is stored or retrieved.

The following table describes the entry types for text files.

Entry Description
;comments You can optionally include comments throughout a text file. You must prefix a comment with a semicolon or a number sign (#). Comments can help to explain how the resources are organized. For example, you might organize your resources in a particular file by labeling them with comments such as ;exceptions, ;general messages, ;text labels, ;form titles, and so on. Note that these comments are lost when you convert a .txt file into a .resources file.
name = value You must specify the string resources as name/value pair entries, where the name is a string that describes the resource and the value is the resource string that will be returned when the name is retrieved by the ResourceManager.GetString method. The name and the value must be separated by an equal sign (=). For example, Msg1 = Hello, and Welcome! The value cannot contain new line characters, but you can use C language-style escape characters such as \n to represent a new line and \t to represent a tab.

Once you have added all the desired entries to your text file, save it with an appropriate name and the .txt extension.

Note   Do not use resource files to store passwords, security-sensitive information, or private data.

You cannot embed a .txt file in an assembly. You must convert your .txt file into a .resources file using the Resource File Generator (Resgen.exe). For more information, see Resources in .Resources File Format.

See Also

Creating Resource Files | Resources in .Resources File Format | Resource File Generator (Resgen.exe)

Show:
© 2014 Microsoft