Reputation: 733
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?
Upvotes: 0
Views: 3561
Reputation: 99987
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);
}
}
Upvotes: 3