VirtualFile コンストラクタ
アセンブリ: System.Web (system.web.dll 内)


カスタム VirtualPathProvider オブジェクトによって提供された DataSet オブジェクトから仮想ファイル情報を取得する VirtualFile コンストラクタを実装する方法を次のコード例に示します。例の実行に必要なコード全体については、VirtualFile クラスの概要で「例」を参照してください。
Public Sub New(ByVal virtualPath As String, ByVal provider As SamplePathProvider) MyBase.New(virtualPath) 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 ' Get the virtual file data from the resource table. Dim files As DataTable files = ds.Tables("resource") Dim rows As DataRow() rows = files.Select( _ String.Format("(name='{0}') AND (type='file')", Me.Name)) ' If the select returned a row, store the file contents. If (rows.Length > 0) Then Dim row As DataRow row = rows(0) content = row("content").ToString() End If End Sub
public SampleVirtualFile(string virtualPath, SamplePathProvider provider) : base(virtualPath) { this.spp = provider; GetData(); } protected void GetData() { // Get the data from the SamplePathProvider DataSet ds = spp.GetVirtualData(); // Get the virtual file from the resource table. DataTable files = ds.Tables["resource"]; DataRow[] rows = files.Select( String.Format("(name = '{0}') AND (type='file')", this.Name)); // If the select returned a row, store the file contents. if (rows.Length > 0) { DataRow row = rows[0]; content = row["content"].ToString(); } }

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- VirtualFile コンストラクタのページへのリンク