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 . 이 코드는 개체에 로드되는 데이터 저장소의 가상 리소스를 제공하기 위해 클래스 및 VirtualPathProvider 클래스에 대한 VirtualFile 코드 예제와 DataSet 함께 작동합니다. 예제를 컴파일하고 실행하기 위한 전체 지침은 클래스 개요의 예제 섹션을 VirtualPathProvider 참조하세요.

이 예제에는 클래스 구현과 개체를 VirtualDirectory 채우는 DataSet 데 사용되는 XML 데이터 파일의 두 부분이 있습니다.

첫 번째 코드 예제는 클래스의 구현입니다 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

두 번째 예제는 사용자 지정 DataSet 개체에서 반환된 개체를 VirtualPathProvider 채우는 데 사용되는 XML 데이터 파일입니다. 이 XML 데이터는 , 및 VirtualPathProvider 클래스를 사용하여 VirtualFileVirtualDirectory외부 데이터에서 데이터를 검색하는 방법을 보여 주는 데 사용되며 프로덕션 품질 데이터 저장소를 나타내기 위한 것이 아닙니다.

<?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 해야 합니다.

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

생성자

Name Description
VirtualDirectory(String)

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

속성

Name Description
Children

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

Directories

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

Files

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

IsDirectory

디렉터리로 처리해야 하는 가상 리소스임을 나타내는 값을 가져옵니다.

Name

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

(다음에서 상속됨 VirtualFileBase)
VirtualPath

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

(다음에서 상속됨 VirtualFileBase)

메서드

Name Description
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)

적용 대상

추가 정보