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?
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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With