473,378 Members | 1,489 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,378 software developers and data experts.

Resources

Greetings,

When I add a resource to the project (VS.NET) it places a .resx file. There
are many columns in the grid to input data. I just want to specify a
Name/Value pair to hold a resource of strings.

My problem is that I also have to specify a type. So I usually specify
System.String. I have no idea what I would put in there. I also have a
difficult time locating information about this topic. Most of the resources
I can find on this topic are not as straightforward as I'd like them to be.
I have "Professional C# 1st Ed.", "C# for Experience Programmers", and a few
others. MSDN isn't terribly helpful. Googling turns up too many results to
be useful but at the same time, I haven't found my answer in the first 3
pages.

I want to be able to add a Resx file. Specify a Name/Value pair. In my
code, look up the Name and be able to use the value. Sounds simple, right?
I've tried using the ResourceManager class available in most examples but it
always fails.

What must I do? I don't want to resource to using a .txt file for my
resources.
Thanks,
Shawn
Nov 15 '05 #1
3 3518
Is it for an executable or a web application? If so you can look at using either an appname.exe.config or web.config respectively. Take a look at the System.Configuration namespace for more info

For libraries (dll's) there isn't a clean way to get name/value properties that I know of.

~harri
weblog: http://www.harrisreynolds.net/weblog
Nov 15 '05 #2
Hi Shawn

I had faced a similar problem a few months back - I had to put a lot of message strings and their corresponding message types in a resx and then load it, when a message is to be presented to the user. What I did was as follows

I defined all possible message types in a Messages enumeration. I also defined a class to wrap the implementation. For all these messages, the corresponsing message strings, button types, and icons are stored in the <classname>.resx resource file. When the class loads, it's resource manager member loads the resx file. I defined a static method ShowMessage in the class, which accepts a Messages enumeration value. This would take the values from the resx file and show the required messagebox.

In the resx, the 'name' column will have exactly the same name as that of the Messages enum values. Their corresponsing 'value' column will have the message to be displayed. This type would be System.String. If you need to put the buttons requires, and Icon to be show, set the value to the enum value and set the type to say System.Windows.Forms.MessageBoxButtons

To load the resource use
private static System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof <class name>))

To show the message
MessageBox.Show
resources.GetString(msgMessageType.ToString()) + ((ExtendedMessage==string.Empty)?string.Empty : ("\r\n\r\nMore info:\r\n" + ExtendedMessage))
"<title>"
(MessageBoxButtons)resources.GetObject(msgMessageT ype.ToString() + "Buttons")
(MessageBoxIcon)resources.GetObject(msgMessageType .ToString() + "Icon"
)

HTH
fbhca

Nov 15 '05 #3
I did as you said. I added an Resx file to an empty project, title it
"Strings".

Then I add the following code:

resource = new ResourceManager(typeof(Strings));
MessageBox.Show(resource.GetString("ALERT"));
In the resx data section, I added "Name" = "ALERT" "Value" = "This is an
alert" and "Type" = "System.String"

But this won't compile because of typeof(Strings) where strings is not a
member of the project. Am I missing something?
Thanks,
Shawn
"fbhcah" <an*******@discussions.microsoft.com> wrote in message
news:F3**********************************@microsof t.com...
Hi Shawn,

I had faced a similar problem a few months back - I had to put a lot of message strings and their corresponding message types in a resx and then
load it, when a message is to be presented to the user. What I did was as
follows.
I defined all possible message types in a Messages enumeration. I also defined a class to wrap the implementation. For all these messages, the
corresponsing message strings, button types, and icons are stored in the
<classname>.resx resource file. When the class loads, it's resource manager
member loads the resx file. I defined a static method ShowMessage in the
class, which accepts a Messages enumeration value. This would take the
values from the resx file and show the required messagebox.
In the resx, the 'name' column will have exactly the same name as that of the Messages enum values. Their corresponsing 'value' column will have the
message to be displayed. This type would be System.String. If you need to
put the buttons requires, and Icon to be show, set the value to the enum
value and set the type to say System.Windows.Forms.MessageBoxButtons.
To load the resource use:
private static System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof <class name>));
To show the message:
MessageBox.Show(
resources.GetString(msgMessageType.ToString()) + ((ExtendedMessage==string.Empty)?string.Empty : ("\r\n\r\nMore info:\r\n" +
ExtendedMessage)), "<title>",
(MessageBoxButtons)resources.GetObject(msgMessageT ype.ToString() + "Buttons"), (MessageBoxIcon)resources.GetObject(msgMessageType .ToString() + "Icon")
);

HTH,
fbhcah

Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Derick Smith | last post by:
Hi! I am just starting to use .NET and need some help! If I create my own DLL for String resouces using this command: C:\WINNT\MICROS~1.NET\Framework\v1.1.4322\Al /t:lib...
3
by: Jesse | last post by:
Hi together, I've a problem with compiling an application with a build-Script and run it after. Several resource-files I compile with resgen.exe and put the files into a folders of the...
1
by: Stefan Turalski \(stic\) | last post by:
Hi, What I need to do is adding some support for resources files to my application. What I did is: MyAppMain <- startup project MyAppHelper <- project which has MyAppResourcesClass (al a...
4
by: Rachel Suddeth | last post by:
What is the difference between a managed/unmanaged resource, and how do you tell which is which? I'm trying to understand how to write some Dispose() methods, and we are supposed to put code that...
4
by: Jon Rista | last post by:
I have a project where I need to create a windows .exe by compiling code and linking in some resources. This program thats being generated is somewhat unconventional, and I'll explain how. I'm...
0
by: Johann Blake | last post by:
I'm having trouble grasping how ASP.NET correctly locates resources. There is plenty of documentation on this subject but some things are not clear at all. In my ASP.NET application, I have...
0
by: Derick Smith | last post by:
Hi! I am just starting to use .NET and need some help! If I create my own DLL for String resouces using this command: C:\WINNT\MICROS~1.NET\Framework\v1.1.4322\Al /t:lib...
0
by: Rob Dob | last post by:
Hi, I have a VS2003 C# asp.net project that has been converted into a VS2005 project. Everything seemed to work well until I make a modification to anything within the Component Designer...
1
by: spencermiles | last post by:
Hello, I'm working on a large solution, comprised on numerous Projects, and I would like to have one central projects that contains a set of global RESX Resources. It doesn't make sense to have...
0
by: shamirza | last post by:
· When was .NET announced? Bill Gates delivered a keynote at Forum 2000, held June 22, 2000, outlining the .NET 'vision'. The July 2000 PDC had a number of sessions on .NET technology, and...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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...

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.