473,406 Members | 2,208 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Use a text file as a resource file in C#

Hey all,
I am trying to separate my translation text from my application. To do this, I would like to use resources, but as a text file. I saw that you can create a text file that looks like the following:

MyKey=MyText
MyKey2=MyText2

etc.

What I am wondering is, is there a nice way to access this file and get it by the key, like properties files in java?

I tried this, but it doesn't seem to work:
ResourceManager manager1 = ResourceManager.CreateFileBasedResourceManager("Te stResources.en-US.txt", loc, typeof(string));
Console.WriteLine("Reached: {0}", manager1.GetString("MyTestResource"));

Thanks in advance.
Apr 11 '08 #1
5 2877
Curtis Rutland
3,256 Expert 2GB
Hey all,
I am trying to separate my translation text from my application. To do this, I would like to use resources, but as a text file. I saw that you can create a text file that looks like the following:

MyKey=MyText
MyKey2=MyText2

etc.

What I am wondering is, is there a nice way to access this file and get it by the key, like properties files in java?

I tried this, but it doesn't seem to work:
ResourceManager manager1 = ResourceManager.CreateFileBasedResourceManager("Te stResources.en-US.txt", loc, typeof(string));
Console.WriteLine("Reached: {0}", manager1.GetString("MyTestResource"));

Thanks in advance.
Try Settings. If you are using a Windows Forms solution in Visual Studio, look in your project's Properties file. There will be a file called Settings.settings
If you open it, you can create keys and set default values. You can also set whether these are user-level or application-level settings.

You can get to this from your code with:
Expand|Select|Wrap|Line Numbers
  1. Properties.Settings.Default["keyname"];
  2.  
For that matter, it doesn't even have to be a Windows Forms project. Even in a console application you can add a Settings.settings file and move it to the properties folder.
Apr 11 '08 #2
Try Settings. If you are using a Windows Forms solution in Visual Studio, look in your project's Properties file. There will be a file called Settings.settings
If you open it, you can create keys and set default values. You can also set whether these are user-level or application-level settings.

You can get to this from your code with:
Expand|Select|Wrap|Line Numbers
  1. Properties.Settings.Default["keyname"];
  2.  
For the translations, we want to allow them to be updatable outside of compile time. Ie, so that someone can edit the translations, and the application just uses them. Is there a way to basically do a properties file (or ResourceBundle in Java), that will achieve this?

Ideally, I would like to have a file called: Translations.txt, and then use the resource manager to handle it, and allow me to use ResourceManager.GetString("Key");

Is this possible with resources, or should I be looking else where? My understanding is the Settings file isn't updatable after compiling?
Apr 11 '08 #3
Curtis Rutland
3,256 Expert 2GB
For the translations, we want to allow them to be updatable outside of compile time. Ie, so that someone can edit the translations, and the application just uses them. Is there a way to basically do a properties file (or ResourceBundle in Java), that will achieve this?

Ideally, I would like to have a file called: Translations.txt, and then use the resource manager to handle it, and allow me to use ResourceManager.GetString("Key");

Is this possible with resources, or should I be looking else where? My understanding is the Settings file isn't updatable after compiling?
It actually is updateable. If you look in your bin\(debug/release) folder, you should see an exe file. Also, there is a .config file with the same name as the .exe. That config file is an xml file that holds the keys that you defined. So, if you just want to be able to edit the keys with a text editor after compile, you still can. Also, if you are making a windows installer package, it should install both the exe and the .config file, so you can make configuration changes there.

Maybe not quite what you were looking for, but that's how I know how to do it.
Apr 11 '08 #4
It actually is updateable. If you look in your bin\(debug/release) folder, you should see an exe file. Also, there is a .config file with the same name as the .exe. That config file is an xml file that holds the keys that you defined. So, if you just want to be able to edit the keys with a text editor after compile, you still can. Also, if you are making a windows installer package, it should install both the exe and the .config file, so you can make configuration changes there.

Maybe not quite what you were looking for, but that's how I know how to do it.
Will that still give the ability to change the language? With the resource files, you can have english, french, etc easily.
Apr 11 '08 #5
Curtis Rutland
3,256 Expert 2GB
Will that still give the ability to change the language? With the resource files, you can have english, french, etc easily.
Hmm. Tough one. I haven't ever had to work with translations, so I guess I was missing the point. So I'm not really sure. But if you just want to set up a file with keys and values, and then edit those values later with a text editor, then yes this will work.
Apr 11 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Ola Theander | last post by:
Dear subscribers I'm currently creating a small application that will run at the end of a web installation to configure a SQL Server. For this task I have a SQL batch file in the same format...
6
by: J. Shrimp, Jr. | last post by:
Following code exports tables as text files: For Each tdf In db.TableDefs StrTblName = tdf.Name Me.txtProgName = StrTblName Me.txtProgName.Requery tblAtt = tdf.Attributes moddate =...
1
by: john s | last post by:
I am trying to create a message text file for the Catagory field in order to map the catagory input number to a string text. I have found some MSDN information on this, but it appears to only be...
3
by: Ron Vecchi | last post by:
I have a text file(.js) that holds a buch of java script code that is rendered in some web controls all part of a larger webcontrol library. The file is rather large. Would embedding this...
1
by: Bruce | last post by:
I would like to store a text file as an embedded resource, and then at runtime read it in as if it were a text file on the hard drive. Is this possible? --Bruce
0
by: Kevin Frey | last post by:
I am relatively new to ASP.NET development. We have built an assembly in C++ (mixed mode) that will be used by our ASP.NET application. The assembly can also be used outside of ASP.NEt. ...
2
by: Chris Murphy via DotNetMonster.com | last post by:
Hey all, just wondering if anyone can point me in the right direction. I'm developing a solution that allows a user to store multiple text-based content (like code snippets, notes, documents etc.)...
4
by: David | last post by:
I have an application that creates a database from a text file of DDL (generated by Visio). Currently I have to deploy the text file with my application and open it using the statement: SQL =...
1
by: Jon Paal | last post by:
trying to embed a text file as a resource when compiling with vbc.exe /resource: "readme.txt" error returned is asking for <resinfo> what is "<resinfo" and what is correct command line...
1
by: agarwalsunitadhn | last post by:
Hi I am developing an application in which i need to convert a text file into a resource file and then serach different resources from the resource file. I want to know how to create the resource...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.