HierarchicalDataSourceView.Select 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
보기에 있는 모든 데이터 항목의 목록을 가져옵니다.
public:
abstract System::Web::UI::IHierarchicalEnumerable ^ Select();
public abstract System.Web.UI.IHierarchicalEnumerable Select();
abstract member Select : unit -> System.Web.UI.IHierarchicalEnumerable
Public MustOverride Function Select () As IHierarchicalEnumerable
반품
IHierarchicalEnumerable 데이터 항목의 컬렉션입니다.
예제
다음 코드 예제에서는 파일 시스템에서 계층적 Select 데이터를 검색하기 위해 클래스에서 HierarchicalDataSourceView 파생되는 클래스의 메서드를 재정 FileSystemInfo 의하는 방법을 보여 줍니다. 보안을 위해 파일 시스템 정보는 데이터 원본 제어가 localhost, 인증된 시나리오에서 사용되는 경우에만 표시되며, 데이터 원본 제어를 사용하는 Web Forms 페이지가 상주하는 가상 디렉터리로만 시작합니다. 그렇지 않으면 viewPath 뷰 개체의 생성자에 전달된 매개 변수를 사용하여 현재 파일 시스템 경로를 기반으로 보기를 만들 수 있습니다. 이 코드 예제는 클래스에 제공된 더 큰 예제의 HierarchicalDataSourceControl 일부입니다.
public class FileSystemDataSourceView : HierarchicalDataSourceView
{
private string _viewPath;
public FileSystemDataSourceView(string viewPath)
{
HttpRequest currentRequest = HttpContext.Current.Request;
if (viewPath == "")
{
_viewPath = currentRequest.MapPath(currentRequest.ApplicationPath);
}
else
{
_viewPath = Path.Combine(
currentRequest.MapPath(currentRequest.ApplicationPath),
viewPath);
}
}
// Starting with the rootNode, recursively build a list of
// FileSystemInfo nodes, create FileSystemHierarchyData
// objects, add them all to the FileSystemHierarchicalEnumerable,
// and return the list.
public override IHierarchicalEnumerable Select()
{
HttpRequest currentRequest = HttpContext.Current.Request;
// SECURITY: There are many security issues that can be raised
// SECURITY: by exposing the file system structure of a Web server
// SECURITY: to an anonymous user in a limited trust scenario such as
// SECURITY: a Web page served on an intranet or the Internet.
// SECURITY: For this reason, the FileSystemDataSource only
// SECURITY: shows data when the HttpRequest is received
// SECURITY: from a local Web server. In addition, the data source
// SECURITY: does not display data to anonymous users.
if (currentRequest.IsAuthenticated &&
(currentRequest.UserHostAddress == "127.0.0.1" ||
currentRequest.UserHostAddress == "::1"))
{
DirectoryInfo rootDirectory = new DirectoryInfo(_viewPath);
if (!rootDirectory.Exists)
{
return null;
}
FileSystemHierarchicalEnumerable fshe =
new FileSystemHierarchicalEnumerable();
foreach (FileSystemInfo fsi
in rootDirectory.GetFileSystemInfos())
{
fshe.Add(new FileSystemHierarchyData(fsi));
}
return fshe;
}
else
{
throw new NotSupportedException(
"The FileSystemDataSource only " +
"presents data in an authenticated, localhost context.");
}
}
}
Public Class FileSystemDataSourceView
Inherits HierarchicalDataSourceView
Private _viewPath As String
Public Sub New(ByVal viewPath As String)
Dim currentRequest As HttpRequest = HttpContext.Current.Request
If viewPath = "" Then
_viewPath = currentRequest.MapPath(currentRequest.ApplicationPath)
Else
_viewPath = Path.Combine(currentRequest.MapPath(currentRequest.ApplicationPath), viewPath)
End If
End Sub
' Starting with the rootNode, recursively build a list of
' FileSystemInfo nodes, create FileSystemHierarchyData
' objects, add them all to the FileSystemHierarchicalEnumerable,
' and return the list.
Public Overrides Function [Select]() As IHierarchicalEnumerable
Dim currentRequest As HttpRequest = HttpContext.Current.Request
' SECURITY: There are many security issues that can be raised
' SECURITY: by exposing the file system structure of a Web server
' SECURITY: to an anonymous user in a limited trust scenario such as
' SECURITY: a Web page served on an intranet or the Internet.
' SECURITY: For this reason, the FileSystemDataSource only
' SECURITY: shows data when the HttpRequest is received
' SECURITY: from a local Web server. In addition, the data source
' SECURITY: does not display data to anonymous users.
If currentRequest.IsAuthenticated AndAlso _
(currentRequest.UserHostAddress = "127.0.0.1" OrElse _
currentRequest.UserHostAddress = "::1") Then
Dim rootDirectory As New DirectoryInfo(_viewPath)
Dim fshe As New FileSystemHierarchicalEnumerable()
Dim fsi As FileSystemInfo
For Each fsi In rootDirectory.GetFileSystemInfos()
fshe.Add(New FileSystemHierarchyData(fsi))
Next fsi
Return fshe
Else
Throw New NotSupportedException( _
"The FileSystemDataSource only " + _
"presents data in an authenticated, localhost context.")
End If
End Function 'Select
End Class
설명
메서드는 Select 현재 보기에서 데이터 항목의 컬렉션을 반환 IHierarchicalEnumerable 합니다. 메서드를 GetEnumerator 호출하여 개체를 IEnumerator 가져오고 데이터 항목 컬렉션을 반복할 수 있습니다.