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