【问题标题】:Physical path of usercontrol (asp.net)usercontrol的物理路径(asp.net)
【发布时间】:2010-09-15 16:49:42
【问题描述】:

我在获取用户控件的路径时遇到了问题。场景如下:

在 aspx 中,我有多个用户控件。在其中一个用户控件中,我需要遍历其他用户控件并获取它们的物理路径。有什么简单的方法吗?

【问题讨论】:

    标签: .net asp.net path


    【解决方案1】:
    List<string> GetUserControlPathsForPage { 
         var list = new List<string>();
         return getUserControlPathsRecursive(Page.Controls, list);
     } 
    
    void getPathsRecursive(ControlCollection controls, List<string> list) {  
         foreach (var c in controls) {  
            var uc = c as UserControl;
            if (uc != null) { 
                list.Add(Server.MapPath(uc.AppRelativeVirtualPath));
            }
            getPathsRecursive(c.Controls,list);
         }
     }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-05
      • 2011-08-17
      • 1970-01-01
      • 1970-01-01
      • 2011-02-19
      • 1970-01-01
      相关资源
      最近更新 更多