zoukankan      html  css  js  c++  java
  • DNN编译后找不到资源文件

    DNN编译后找不到资源文件,大概要改一下程序才能用,下面是找的代码片断,有这方面经验的好手们,方便的话就指点下,谢谢

    ////////////////////////////
     ASP.NET操作资源文件

    转自:http://tb.blog.csdn.net/TrackBack.aspx?PostId=1653141

    在上次的一个国际化项目中用到资源文件,在.NET中对资源文件的访问很多人遇到过同样的麻烦,在这里跟大家共享一种方法,希望能对初学者有所帮助.

       private string GetGlobalResourceString(string className, string resourceKey)
        {
            Type type = GetResourceType(className);
            return type.GetProperty(resourceKey).GetValue(null, null) as string;
        }

        private Type GetResourceType(string name)
        {
            return (Assembly.Load("App_GlobalResources")).GetType("Resources." + name);
        }

    //在Page_Load中将值打印出来
    //资源文件名为:john.strings.resx
    //中有key : john    value : xizhaohui
    //程序运行将在页面打印 "xizhaohui"
      protected void Page_Load(object sender, EventArgs e)
        {
            Response.Write(GetGlobalResourceString("john.strings", "john"));
        }

     

    Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1653141

    转自:http://tb.blog.csdn.net/TrackBack.aspx?PostId=1653141

    ///////////////////////

    asp.net2.0读取资源文件的方式整理


    方法一
    System.Web.HttpContext.GetGlobalResourceObject("Resource", "Name").ToString()

     
    方法二

       private string GetGlobalResourceString(string className, string resourceKey)
        {
            Type type = GetResourceType(className);
            //type.GetProperty("Culture").SetValue(null, new CultureInfo("zh-cn"), null);

            return type.GetProperty(resourceKey).GetValue(null, null) as string;
        }
        private Type GetResourceType(string name)
        {
            Assembly ass = Assembly.Load("App_GlobalResources");
            Type type = ass.GetType("Resources." + name);
            return type;
        }

    /////////////////////////////////

    在ASP.net中有两个固定文件夹App_GlobalResources和App_LocalResources,其中App_GlobalResources会编译到App_GlobalResources.dll中,用于存放公用的资源,App_LocalResources不执行编译,用于存放各个页面自己的资源。在Page和UserControl的基类TemplateControl中新增了GetGlobalResourceObject和GetLocalResourceObject两个函数,可以在页面中直接调用(在HttpContext中也有两个同样的静态方法)以取得指定的资源。
            例如:在App_GlobalResources中有个test.strings.resx的资源文件,里面有条名为s的资源,则可以使用GetGlobalResourceObject("test.strings", "s")来取得它,这里没有指定取得何种语言的资源,这样的话将会使用Thread.CurrentThread.CurrentUICulture中的语言,自己也可以在使用之前设定Thread.CurrentThread.CurrentUICulture的值。可以没有test.strings.resx这个文件,直接使用test.strings.zh-cn.resx、test.strings.en-us.resx...等文件。
            还有很多方法可以取得资源,这里写出一个,不同的是必须有test.strings.resx这个文件。可以直接使用Resources.test.strings.s来取得资源,这样子做感觉不够灵活,可以模仿GetGlobalResourceObject方法写一个GetGlobalResourceString方法,如下:
        private string GetGlobalResourceString(string className, string resourceKey)
        {
            Type type = GetResourceType(className);
            //type.GetProperty("Culture").SetValue(null, new CultureInfo("zh-cn"), null);

            return type.GetProperty(resourceKey).GetValue(null, null) as string;
        }
        private Type GetResourceType(string name)
        {
            Assembly ass = Assembly.Load("App_GlobalResources");
            Type type = ass.GetType("Resources." + name);
            return type;
        }



    Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=624763


     

  • 相关阅读:
    【POJ】1067 取石子游戏(博弈论)
    【POJ】2348 Euclid's Game(扩欧)
    【POJ】1061 青蛙的约会 / 【BZOJ】1477(扩欧)
    【POJ】3090 Visible Lattice Points(欧拉函数)
    【BZOJ】2190 [SDOI2008]仪仗队(欧拉函数)
    【POJ】2115 C Looooops(扩欧)
    【BZOJ】1015 [JSOI2008]星球大战starwar(并查集+离线处理)
    [BZOJ4822][Cqoi2017]老C的任务
    [BZOJ1001][BeiJing2006]狼抓兔子
    [BZOJ1188][HNOI2007]分裂游戏
  • 原文地址:https://www.cnblogs.com/shiningrise/p/800228.html
Copyright © 2011-2022 走看看