简体   繁体   中英

How to read from a resx file in the App_LocalResources folder using a specific culture?

To read a resource for a default culture I'd do this:

object obj = GetLocalResourceObject("MyTextResourceID.Text");

But what I need is to do the same but to be able to specify a culture for the resource. So I tried this:

System.Globalization.CultureInfo cultInfo = 
    new System.Globalization.CultureInfo("en-US");

object obj = HttpContext.GetLocalResourceObject(
    "~/" + Path.GetFileName(this.Request.PhysicalPath), 
    "MyTextResourceID.Text", 
    cultInfo);

but it always returns obj as null. Any idea why?

OK. As suggested above, I'm answering my own question. The code above is correct and works just fine. My problem was that the resource with such ID did not exist in all .resx files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM