VirtualDirectoryとは? わかりやすく解説

VirtualDirectory クラス

メモ : このクラスは、.NET Framework version 2.0新しく追加されたものです。

仮想ファイルまたはリソース領域ディレクトリ オブジェクト表します

名前空間: System.Web.Hosting
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public MustInherit Class
 VirtualDirectory
    Inherits VirtualFileBase
Dim instance As VirtualDirectory
public abstract class VirtualDirectory : VirtualFileBase
public ref class VirtualDirectory abstract
 : public VirtualFileBase
public abstract class VirtualDirectory extends
 VirtualFileBase
public abstract class VirtualDirectory extends
 VirtualFileBase
解説解説
使用例使用例

DataSet オブジェクト格納されている仮想ディレクトリ情報返す VirtualDirectory クラス実装例次のコード示します。このコードは、VirtualPathProvider クラスおよび VirtualFile クラスコード例連携してDataSet オブジェクト読み込まれデータ ストアから仮想リソース返します例のコンパイルおよび実行のための手全体については、VirtualPathProvider クラス概要で「例」を参照してください

この例は、VirtualDirectory クラス実装と、DataSet オブジェクト設定使用される XML データ ファイルという 2 つ部分構成されます。

最初コード例では、VirtualDirectory クラス実装する方法示してます。この例のコンストラクタでは、VirtualPathProvider カスタム オブジェクトメソッド使用して DataSet オブジェクト返してます。次にDataSet オブジェクト検索して指定した仮想パス関連付けられたディレクトリ情報取得します

Imports Microsoft.VisualBasic

Imports System
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
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; }
    }
  }
  

2 番目の例では、VirtualPathProvider カスタム オブジェクトにより返されDataSet オブジェクト設定するために使用される XML データ ファイル示してます。この XML データVirtualPathProviderVirtualFile、および 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>
継承階層継承階層
System.Object
   System.MarshalByRefObject
     System.Web.Hosting.VirtualFileBase
      System.Web.Hosting.VirtualDirectory
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
VirtualDirectory メンバ
System.Web.Hosting 名前空間

VirtualDirectory コンストラクタ

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

VirtualDirectory クラス新しインスタンス初期化します。

名前空間: System.Web.Hosting
アセンブリ: System.Web (system.web.dll 内)
構文構文

Protected Sub New ( _
    virtualPath As String _
)
Dim virtualPath As String

Dim instance As New VirtualDirectory(virtualPath)
protected VirtualDirectory (
    string virtualPath
)
protected:
VirtualDirectory (
    String^ virtualPath
)
protected VirtualDirectory (
    String virtualPath
)
protected function VirtualDirectory (
    virtualPath : String
)

パラメータ

virtualPath

このインスタンスによって表されるリソースへの仮想パス

使用例使用例

VirtualPathProvider カスタム オブジェクトによって提供されDataSet オブジェクトから仮想ファイル情報取得する VirtualDirectory コンストラクタ実装例次のコード示します。この例には、VirtualDirectory インスタンス設定使用されるGetData メソッド含まれています。例の実行必要なコード全体については、VirtualDirectory クラス概要で「例」を参照してください

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
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);
      }
    }
  }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
VirtualDirectory クラス
VirtualDirectory メンバ
System.Web.Hosting 名前空間

VirtualDirectory プロパティ


VirtualDirectory メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
参照参照

関連項目

VirtualDirectory クラス
System.Web.Hosting 名前空間

VirtualDirectory メンバ

仮想ファイルまたはリソース領域ディレクトリ オブジェクト表します

VirtualDirectory データ型公開されるメンバを以下の表に示します


プロテクト コンストラクタプロテクト コンストラクタ
  名前 説明
プロテクト メソッド VirtualDirectory VirtualDirectory クラス新しインスタンス初期化します。
パブリック プロパティパブリック プロパティ
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

VirtualDirectory クラス
System.Web.Hosting 名前空間



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「VirtualDirectory」の関連用語

VirtualDirectoryのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



VirtualDirectoryのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS