tags:

views:

933

answers:

1

I have a problem regarding getting the path of a user control. The scenario is as follows:

In a aspx i have multiple user controls. In one of those user conrtols i need to loop through the other user controls and get the physical path of them. Is there any easy way to do this?

+1  A: 
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);
     }
 }
Mark Cidade