在Application_Start上请求App_GlobalResources目录

时间:2011-12-28 05:34:06

标签: c# asp.net

问你在Application_Start全局asax中为请求做了什么我想要替换我的App_GlobalResources目录的路径但是我尝试使用请求并且它不起作用我错过了程序集引用是否有另一种方法。

更新代码:

List<string> languages = new List<string>
foreach (var file in Directory.EnumerateFiles(HttpContext.Current.Request.MapPath("App_GlobalResources"), "*.resx"))
{
    string resource = Path.GetFileNameWithoutExtension(file);
    if (resource.Length > 9)
    {
        string filename = resource.Substring(resource.IndexOf(".") + 1, resource.Length - resource.IndexOf(".") - 1);
        RegionInfo regionInfo = new RegionInfo(filename);
        if (!string.IsNullOrEmpty(filename))
        {
            llanguages.Add(filename);

         } // error here
    }
} 
HttpContext.Current.Application.Add("Cultures", languages.ToArray());

1 个答案:

答案 0 :(得分:1)

List<string> languages = new List<string>(); 
 foreach (var file in Directory.EnumerateFiles("C:\\Users\\KIRK\\Documents\\Visual Studio 2010\\WebSites\\WebSite2\\App_GlobalResources", "*.resx")) 
 {
 string resource = Path.GetFileNameWithoutExtension(file);  
 if (resource.Length > 9)     {       
 string filename = resource.Substring(resource.IndexOf(".") + 1, resource.Length - resource.IndexOf(".") - 1);         
 RegionInfo regionInfo = new RegionInfo(filename);        
 if (!string.IsNullOrEmpty(filename))     
 {             languages.Add(filename);  
                } 
 } 
 } 
 HttpContext.Current.Application.Add("Cultures", languages.ToArray());