USERCONTROL (ASP.NET)의 물리적 경로
문제
사용자 컨트롤의 경로를 얻는 데 문제가 있습니다. 시나리오는 다음과 같습니다.
ASPX에는 여러 사용자 컨트롤이 있습니다. 해당 사용자 Conrtols 중 하나에서는 다른 사용자 컨트롤을 통과하고 물리적 경로를 가져와야합니다. 이 작업을 수행하는 쉬운 방법이 있습니까?
해결책
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);
}
}
제휴하지 않습니다 StackOverflow