VirtualDirectory(String) 생성자

정의

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

protected:
 VirtualDirectory(System::String ^ virtualPath);
protected VirtualDirectory (string virtualPath);
new System.Web.Hosting.VirtualDirectory : string -> System.Web.Hosting.VirtualDirectory
Protected Sub New (virtualPath As String)

매개 변수

virtualPath
String

이 인스턴스가 나타내는 리소스의 가상 경로입니다.

예제

다음 코드 예제는의 구현 합니다 VirtualDirectory 생성자에서 가상 파일 정보를 검색 하는 DataSet 사용자 지정에서 제공 하는 개체 VirtualPathProvider 개체입니다. 여기에 GetData 채우는 데 사용 되는 메서드는 VirtualDirectory 인스턴스. 예제를 실행 하는 데 필요한 전체 코드의 예제 섹션을 참조 하세요.를 VirtualDirectory 클래스 개요입니다.

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);
      }
    }
  }
}
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

적용 대상

추가 정보