VirtualFile(String) 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 VirtualFile 類別的新執行個體。
protected:
VirtualFile(System::String ^ virtualPath);
protected VirtualFile (string virtualPath);
new System.Web.Hosting.VirtualFile : string -> System.Web.Hosting.VirtualFile
Protected Sub New (virtualPath As String)
參數
- virtualPath
- String
這個執行個體所表示之資源的虛擬路徑。
範例
下列程式碼範例是建構函式的實作 VirtualFile ,可從 DataSet 自訂 VirtualPathProvider 物件所提供的 物件擷取虛擬檔案資訊。 如需執行範例所需的完整程式碼,請參閱類別概觀的 VirtualFile 範例一節。
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();
}
}
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