VirtualDirectory 클래스

정의

가상 파일 또는 리소스 공간의 디렉터리 개체를 나타냅니다.

public ref class VirtualDirectory abstract : System::Web::Hosting::VirtualFileBase
public abstract class VirtualDirectory : System.Web.Hosting.VirtualFileBase
type VirtualDirectory = class
    inherit VirtualFileBase
Public MustInherit Class VirtualDirectory
Inherits VirtualFileBase
상속

예제

다음 코드 예제는 VirtualDirectory 에 저장 된 가상 디렉터리 정보를 반환 하는 클래스 구현을 DataSet 개체입니다. 이 코드에 대 한 코드 예제를 사용 하 여 작동는 VirtualPathProviderVirtualFile 되는 데이터에서 가상 리소스 저장소를 제공 하는 클래스에 로드 되는 DataSet 개체. 컴파일 및 예제를 실행 하는 것에 대 한 전체 지침의 예 섹션을 참조 합니다 VirtualPathProvider 클래스 개요입니다.

이 예제는 두 부분으로 구성 합니다 VirtualDirectory 클래스 구현 및 XML 데이터 파일을 채우는 데는 DataSet 개체.

첫 번째 코드 예제는 구현의 VirtualDirectory 클래스입니다. 생성자에서 사용 하 여 메서드를 사용자 지정 VirtualPathProvider 반환할 개체는 DataSet 개체입니다. 그런 다음 검색는 DataSet 제공 된 가상 경로 연결 된 디렉터리 정보를 검색할 개체입니다.

using System;
using System.Collections;
using System.Data;
using System.Security.Permissions;
using System.Web;
using System.Web.Hosting;

namespace Samples.AspNet.CS
{
  [AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
  [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  public class SampleVirtualDirectory : VirtualDirectory
  {
    SamplePathProvider spp;

    private bool exists;
    public bool Exists
    {
      get { return exists; }
    }

    public SampleVirtualDirectory(string virtualDir, SamplePathProvider provider)
      : base(virtualDir)
    {
      spp = provider;
      GetData();
    }

    protected void GetData()
    {
      DataSet ds = spp.GetVirtualData();

      // Clean up the path to match data in resource file.
      string path = VirtualPath.Replace(HostingEnvironment.ApplicationVirtualPath, "");
      path = path.TrimEnd('/');

      // Get the virtual directory from the resource table.
      DataTable dirs = ds.Tables["resource"];
      DataRow[] rows = dirs.Select(
        String.Format("(name = '{0}') AND (type='dir')", path));

      // If the select returned a row, the directory exists.
      if (rows.Length > 0)
      {
        exists = true;

        // Get children from the resource table.
        // This technique works for small numbers of virtual resources.
        //   Sites with moderate to large numbers of virtual
        //   resources should choose a method that consumes fewer
        //   computer resources.
        DataRow[] childRows = dirs.Select(
          String.Format("parentPath = '{0}'", path));

        foreach (DataRow childRow in childRows)
        {
          string childPath = (string)childRow["path"];

          if (childRow["type"].ToString() == "dir")
          {
            SampleVirtualDirectory svd = new SampleVirtualDirectory(childPath, spp);
            children.Add(svd);
            directories.Add(svd);
          }
          else
          {
            SampleVirtualFile svf = new SampleVirtualFile(childPath, spp);
            children.Add(svf);
            files.Add(svf);
          }
        }
      }
    }

    private ArrayList children = new ArrayList();
    public override IEnumerable Children
    {
      get { return children; }
    }

    private ArrayList directories = new ArrayList();
    public override IEnumerable Directories
    {
      get { return directories; }
    }

    private ArrayList files = new ArrayList();
    public override IEnumerable Files
    {
      get { return files; }
    }
  }
}

Imports System.Data
Imports System.Collections
Imports System.Security.Permissions
Imports System.Web
Imports System.Web.Hosting


Namespace Samples.AspNet.VB
  <AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal), _
   AspNetHostingPermission(SecurityAction.InheritanceDemand, level:=AspNetHostingPermissionLevel.Minimal)> _
  Public Class SampleVirtualDirectory
    Inherits VirtualDirectory

    Private spp As SamplePathProvider

    ' Declare the variable the property uses.
    Private existsValue As Boolean

    Public ReadOnly Property exists() As Boolean
      Get
        Return existsValue
      End Get
    End Property

    Public Sub New(ByVal virtualDir As String, ByVal provider As SamplePathProvider)
      MyBase.New(virtualDir)
      spp = provider
      GetData()
    End Sub

    Protected Sub GetData()
      ' Get the data from the SamplePathProvider.
      Dim spp As SamplePathProvider
      spp = CType(HostingEnvironment.VirtualPathProvider, SamplePathProvider)

      Dim ds As DataSet
      ds = spp.GetVirtualData

      ' Clean up the path to match data in resource file.
      Dim path As String
      path = VirtualPath.Replace(HostingEnvironment.ApplicationVirtualPath, "")
      Dim trimChars() As Char = {"/"c}
      path = path.TrimEnd(trimChars)

      ' Get the virtual directory from the resource table.
      Dim dirs As DataTable
      dirs = ds.Tables("resource")
      Dim rows As DataRow()
      rows = dirs.Select( _
        String.Format("(name = '{0}') AND (type='dir')", path))

      ' If the select returned a row, the directory exits.
      If (rows.Length > 0) Then
        existsValue = True

        ' Get the children from the resource table.
        ' This technique works for small numbers of virtual resources.
        '  Sites with moderate to large numbers of virtual
        '  resources should choose a method that consumes fewer
        '  computer resources.
        Dim childRows As DataRow()
        childRows = dirs.Select( _
          String.Format("parentPath = '{0}'", path))

        For Each childRow As DataRow In childRows
          Dim childPath As String
          childPath = CType(childRow("path"), String)

          If (childRow("type").ToString = "dir") Then
            Dim svd As New SampleVirtualDirectory(childPath, spp)
            childrenValue.Add(svd)
            directoriesValue.Add(svd)
          Else
            Dim svf As New SampleVirtualFile(childPath, spp)
            childrenValue.Add(svf)
            directoriesValue.Add(svf)
          End If
        Next

      End If
    End Sub

    Private childrenValue As ArrayList
    Public Overrides ReadOnly Property Children() As System.Collections.IEnumerable
      Get
        Return childrenValue
      End Get
    End Property

    Private directoriesValue As ArrayList
    Public Overrides ReadOnly Property Directories() As System.Collections.IEnumerable
      Get
        Return directoriesValue
      End Get
    End Property

    Private filesValue As ArrayList
    Public Overrides ReadOnly Property Files() As System.Collections.IEnumerable
      Get
        Return filesValue
      End Get
    End Property
  End Class

End Namespace

두 번째 예제는 XML 데이터 파일을 채우는 데 사용 합니다 DataSet 사용자 지정 하 여 반환 되는 개체 VirtualPathProvider 개체입니다. 이 XML 데이터를 사용 하 여 설명 하기 위해 사용 되는 VirtualPathProvider, VirtualFile, 및 VirtualDirectory 클래스를 외부 데이터에서 데이터를 검색 하며 프로덕션 수준의 데이터 저장소를 나타내는 데 적합 하지 않습니다.

<?xml version="1.0" encoding="utf-8" ?>  
  <resource type="dir"   
    path="/vrDir"   
    parentPath=""   
    content="">  
    <resource type="file"   
      path="/vrDir/Level1FileA.vrf"  
      parentPath="/vrDir"   
      content="This is the content of file Level1FileA." >  
    </resource>  
    <resource type="file"   
      path="/vrDir/Level1FileB.vrf"  
      parentPath="/vrDir"   
      content="This is the content of file Level1FileB.">  
    </resource>  
    <resource type="dir"   
      path="/vrDir/Level2DirA"   
      parentPath="/vrDir"   
      content="">  
        <resource type="file"   
          path="/vrDir/Level2DirA/Level2FileA.vrf"   
          parentPath="/vrDir/Level2DirA"   
          content="This is the content of file Level2FileA." >  
        </resource>  
        <resource type="file"   
          path="/vrDir/Level2DirA/Level2FileB.vrf"  
          parentPath="/vrDir/Level2DirA"   
          content="This is the content of file Level2FileB.">  
        </resource>  
    </resource>  
    <resource type="dir"   
      path="/vrDir/Level2DirB"   
      parentPath="/vrDir"   
      content="">  
      <resource type="file"   
        path="/vrDir/Level2DirB/Level2FileA.vrf"   
        parentPath="/vrDir/Level2DirB"   
        content="This is the content of file Level2FileA." >  
      </resource>  
      <resource type="file"   
        path="/vrDir/Level2DirB/Level2FileB.vrf"  
        parentPath="/vrDir/Level2DirB"   
        content="This is the content of file Level2FileB.">  
       </resource>  
    </resource>  
  </resource>  

설명

VirtualDirectory 클래스는 기본 클래스 가상 파일 시스템의 디렉터리를 나타내는 개체입니다. 일반적으로 하위 항목의 구현 하는 합니다 VirtualDirectory 각각에 대 한 클래스 VirtualPathProvider 웹 애플리케이션에서 하위 클래스입니다.

구현자 참고

클래스에서 상속할 때 인터페이스를 VirtualDirectory 구현하는 개체를 Children반환하려면 , DirectoriesFiles 속성을 재정의 IEnumerable 해야 합니다.

가상 디렉터리 구조에 보통에서 많은 수의 가상 리소스가 포함된 경우 , 또는 Files 속성을 호출ChildrenDirectories하여 가상 디렉터리를 열거할 때 사용되는 시스템 리소스를 최소화해야 합니다.

생성자

VirtualDirectory(String)

VirtualDirectory 클래스의 새 인스턴스를 초기화합니다.

속성

Children

이 가상 디렉터리에 포함된 파일과 하위 디렉터리 목록을 가져옵니다.

Directories

이 디렉터리에 포함된 모든 하위 디렉터리 목록을 가져옵니다.

Files

이 디렉터리에 포함된 모든 파일 목록을 가져옵니다.

IsDirectory

이 항목이 디렉터리로 처리할 가상 디렉터리임을 나타내는 값을 가져옵니다.

Name

가상 리소스의 표시 이름을 가져옵니다.

(다음에서 상속됨 VirtualFileBase)
VirtualPath

가상 파일 경로를 가져옵니다.

(다음에서 상속됨 VirtualFileBase)

메서드

CreateObjRef(Type)

원격 개체와 통신하는 데 사용되는 프록시 생성에 필요한 모든 관련 정보가 들어 있는 개체를 만듭니다.

(다음에서 상속됨 MarshalByRefObject)
Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetLifetimeService()
사용되지 않습니다.

이 인스턴스의 수명 정책을 제어하는 현재의 수명 서비스 개체를 검색합니다.

(다음에서 상속됨 MarshalByRefObject)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
InitializeLifetimeService()

임대가 만들어지는 것을 방지하여 VirtualFileBase 인스턴스에 영구 수명을 제공합니다.

(다음에서 상속됨 VirtualFileBase)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
MemberwiseClone(Boolean)

현재 MarshalByRefObject 개체의 단순 복사본을 만듭니다.

(다음에서 상속됨 MarshalByRefObject)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상

추가 정보