VirtualFile(String) Constructor
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Initializes a new instance of the VirtualFile class.
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)
Parameters
- virtualPath
- String
The virtual path to the resource represented by this instance.
Examples
The following code example is an implementation of the VirtualFile constructor that retrieves virtual file information from a DataSet object provided by a custom VirtualPathProvider object. For the full code required to run the example, see the Example section of the VirtualFile class overview.
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
Applies to
שתף איתנו פעולה ב- GitHub
ניתן למצוא את המקור לתוכן זה ב- GitHub, שם ניתן גם ליצור ולסקור בעיות ולמשוך בקשות. לקבלת מידע נוסף, עיין במדריך התורמים שלנו.