Adding and accessing resource files

Class library usage, coding and language questions.
Skarlso
Posts: 27
Joined: Thu Aug 07, 2008 9:11 am

Adding and accessing resource files

Post by Skarlso » Mon Aug 11, 2008 10:33 am

Hi!

My problem is that i tried to use resource files in a project using the ranorex IDE and not Visual Studio.

I created the resource file, added a string value and tried to access it using resource reader like this :

//Getting Data from the Resource file.
string appToRun;
System.Resources.ResourceReader rr = new ResourceReader("MyData");
IDictionaryEnumerator id = rr.GetEnumerator();
while(id.MoveNext()) {
if (id.Key.Equals("AppToRun")) {
appToRun = id.Value.ToString();
}
}
rr.Close();

First it did not find MyData because it looked for the file, not in project. So okey i entere ../../MyData.resx.

It said the file is not a valid resource file, although i created it with the IDE.

Is there another solution to access and use resource files in ranorex not using Visual Studio?

Thank you,
Gergely.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Post by Support Team » Mon Aug 11, 2008 4:51 pm

Hi Gergely,

Add your existing .resx file to your project by right clicking onto your project and select "Add" -> "Existing item..." on the context menu.

Please try the following code to read string values from your resource file:

Code: Select all

using System.Resources;
using System.Reflection;

ResourceManager resources = new ResourceManager("Namespace.MyData", Assembly.GetExecutingAssembly());
string appToRun = resources.GetString("AppToRun");
Hope this helps.

Regards,
Gabor
Ranorex Support Team

Skarlso
Posts: 27
Joined: Thu Aug 07, 2008 9:11 am

Post by Skarlso » Tue Aug 12, 2008 8:07 am

Thank you very much!!

That helped!