Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Resources with string [closed]

Tags:

c#

I have a lot of txt files in Resources folder. One of them is corner.txt. I can access this file via this code snippet:

Properties.Resources.corner 

I keep file names in string variables. For example:

string fileName = "corner.txt"; 

I want to access this file via:

Properties.Resources.fileName  

Is this possible? How can I access?

like image 787
1teamsah Avatar asked Jul 24 '13 08:07

1teamsah


2 Answers

I solved the problem this code snippet:

string st = Properties.Resources.ResourceManager.GetString(tableName); 

So, I don't use the filename, I use the txt file's string. This is useful for me.

Thanks a lot.

like image 63
1teamsah Avatar answered Sep 27 '22 19:09

1teamsah


You can use Reflection like that:

var type = typeof(Properties.Resources); var property = type.GetProperty(fileName, BindingFlags.Static| BindingFlags.NonPublic|BindingFlags.Public); var value = property.GetValue(null, null); 

or use the ResourceManager like that:

value = Properties.Resources.ResourceManager.GetObject(fileName, Properties.Resources.Culture); 
like image 33
Swift Avatar answered Sep 27 '22 21:09

Swift