By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,742 Members | 2,026 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,742 IT Pros & Developers. It's quick & easy.

Article : Resource File Generator (Resgen.exe .Net FrameWork Tools Series)

P: n/a
Hi All,

This is a resource file generation tool which converts an xml based resource formats to .net resource file i.e. (.resources) and vice-versa.

Today we will see how we will generate

==> .txt files from .resources or .resx files.

==> .resources files from text or .resx files.

==> .resx files from text or .resources files.

Let us start with converting a .txt file to resources or resx file

In order to convert from one type to another we must ensure that the data written in them is in the correct format.

Text files can only contain string resources as name=value pairs. Name here is a string that describes the resource it needs to be

unique and the value is the resource string. All these name value pairs should start from a new line.

Lets create a text file containing 10 name=value pairs;

1) Create a text file name MyText.txt.
2) Type the below name=value pairs

name1=value
name2=value
name3=value
name4=value
name5=value
name6=value
name7=value
name8=value
name9=value
name10=value

3) Type the following command to generate MyResources.resx from MyText.txt.

4) If you duplicated any of the entires you will get the below error message.

error: Duplicate resource key!
Else your resources will be complied successfully with the following message.
Read in 10 resources from 'MyText.txt'
Writing resource file... Done.

5) To generate .resources file from .txt file use the following command resgen MyText.txt MyResources.resources

6) To genereate .txt from .resources file or .resx file use the following commands

resgen MyResources.resx MyTextFromRes.txt
resgen MyResources.resources MyTextFromResources.txt

7) To generate .txt file from resx file or .resource file use the following commands:

resgen MyResources.resx MyTextFromRes.txt
resgen MyResources.resources MyTextFromResources.txt

There are a certain advantages or disadvantages of these format over one another :

1) Text file format name=value pair is very convient ,easy to use and create but can contain only text strings and hence you cannot embed any objects in these files.
2) Resx file format has the data in the xml format and hence you can embed objects. You will also be able to view the binary information about these objects e.g. embedding images in the resource files.

Thus

..Resources file is a binary file which is used by the assemblies
..Resx has the data in an xml format
..txt has the data in name=value format .... gr8 so many ways to represent and use your data.

To use these resource files in your assembly( as a part of your assembly) you will need to embed or link it with main assembly using assembly linker or create satellite assembly.(We will look into detail about this in tommorrow's article).

-- Please post your queries and comments for my articles in the usergroup for the benefit of all. I hope this step from my end is helpful to all of us.

Regards,

Namratha (Nasha)
Nov 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
I see resx file is generated automaticely for .aspx file. do you know how to
generate a resx file for a project automaticely? and how to modify a resource
fileafter it is generate? it seams crash easily. Thanks for help.

cms123

"Namratha Shah (Nasha)" wrote:
Hi All,

This is a resource file generation tool which converts an xml based resource formats to .net resource file i.e. (.resources) and vice-versa.

Today we will see how we will generate

==> .txt files from .resources or .resx files.

==> .resources files from text or .resx files.

==> .resx files from text or .resources files.

Let us start with converting a .txt file to resources or resx file

In order to convert from one type to another we must ensure that the data written in them is in the correct format.

Text files can only contain string resources as name=value pairs. Name here is a string that describes the resource it needs to be

unique and the value is the resource string. All these name value pairs should start from a new line.

Lets create a text file containing 10 name=value pairs;

1) Create a text file name MyText.txt.
2) Type the below name=value pairs

name1=value
name2=value
name3=value
name4=value
name5=value
name6=value
name7=value
name8=value
name9=value
name10=value

3) Type the following command to generate MyResources.resx from MyText.txt.

4) If you duplicated any of the entires you will get the below error message.

error: Duplicate resource key!
Else your resources will be complied successfully with the following message.
Read in 10 resources from 'MyText.txt'
Writing resource file... Done.

5) To generate .resources file from .txt file use the following command resgen MyText.txt MyResources.resources

6) To genereate .txt from .resources file or .resx file use the following commands

resgen MyResources.resx MyTextFromRes.txt
resgen MyResources.resources MyTextFromResources.txt

7) To generate .txt file from resx file or .resource file use the following commands:

resgen MyResources.resx MyTextFromRes.txt
resgen MyResources.resources MyTextFromResources.txt

There are a certain advantages or disadvantages of these format over one another :

1) Text file format name=value pair is very convient ,easy to use and create but can contain only text strings and hence you cannot embed any objects in these files.
2) Resx file format has the data in the xml format and hence you can embed objects. You will also be able to view the binary information about these objects e.g. embedding images in the resource files.

Thus

..Resources file is a binary file which is used by the assemblies
..Resx has the data in an xml format
..txt has the data in name=value format .... gr8 so many ways to represent and use your data.

To use these resource files in your assembly( as a part of your assembly) you will need to embed or link it with main assembly using assembly linker or create satellite assembly.(We will look into detail about this in tommorrow's article).

-- Please post your queries and comments for my articles in the usergroup for the benefit of all. I hope this step from my end is helpful to all of us.

Regards,

Namratha (Nasha)

Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.