방법에 관한 것이다. 내가 사용하는 경로에는 약 3800 개의 파일과 375 개의 하위 폴더가 있습니다. 페이지를 렌더링하는 데 약 45 초가 걸리지 만, 내 사용자에게는 받아 들일 수 없으므로이 시간을 줄일 수있는 방법이 있습니다.재귀 디렉토리 구조 리스팅 내가 GET 변수에 의해 제공되는 경로 (루트)에서 시작 아래의 코드를 사용하여 반복적으로 모든 하위 폴더로 가서 목록 항목으로 내용을 디스플레이하고
string output;
protected void Page_Load(object sender, EventArgs e) {
getDirectoryTree(Request.QueryString["path"]);
itemWrapper.InnerHtml = output;
}
private void getDirectoryTree(string dirPath) {
try {
System.IO.DirectoryInfo rootDirectory = new System.IO.DirectoryInfo(dirPath);
foreach (System.IO.DirectoryInfo subDirectory in rootDirectory.GetDirectories()) {
output = output + "<ul><li><a>" + Regex.Replace(subDirectory.Name, "_", " ");
if (subDirectory.GetFiles().Length != 0 || subDirectory.GetDirectories().Length != 0) {
output = output + " +</a>";
} else {
output = output + "</a>";
}
getDirectoryTree(subDirectory.FullName);
if (subDirectory.GetFiles().Length != 0) {
output = output + "<ul>";
foreach (System.IO.FileInfo file in subDirectory.GetFiles()) {
output = output + "<li><a href='" + file.FullName + "'>" + file.Name + "</a></li>";
}
output = output + "</ul>";
}
output = output + "</li></ul>";
}
} catch (System.UnauthorizedAccessException) {
//This throws when we don't have access.
}
}
사용자가 확장 된 항목을 한 번에 모두 볼 수 있습니까? 사용자가 구조를 클릭 할 때 필요에 따라 폴더를 가져 오지 않는 이유는 무엇입니까? – Alex
성능 적중의 대부분은 디스크 I/O에있을 것입니다. – Lloyd
@Alex 어떻게 C# + ASP.NET이 새로운 것인가, 나는 Java C# + ASP.NET의 모든 측면을 배우는 Java Certified Associate입니다. –