Share via


Control.TemplateSourceDirectory Properti

Definisi

Mendapatkan direktori Page virtual atau UserControl yang berisi kontrol server saat ini.

public:
 virtual property System::String ^ TemplateSourceDirectory { System::String ^ get(); };
[System.ComponentModel.Browsable(false)]
public virtual string TemplateSourceDirectory { get; }
[<System.ComponentModel.Browsable(false)>]
member this.TemplateSourceDirectory : string
Public Overridable ReadOnly Property TemplateSourceDirectory As String

Nilai Properti

Direktori virtual halaman atau kontrol pengguna yang berisi kontrol server.

Atribut

Contoh

Contoh berikut menggunakan TemplateSourceDirectory properti dua kali. Pertama kali digunakan dalam Control.MapPathSecure panggilan metode untuk mendapatkan jalur ke direktori tempat kontrol berada. Kedua kalinya dalam Directory.GetFiles panggilan metode untuk mendapatkan daftar semua file yang terkandung dalam direktori tersebut.

// An HttpException occurs if the server control does not,;
// have permissions to read the resulting mapped file. 
     output.Write("The Actual Path of the virtual directory : "+
     MapPathSecure(TemplateSourceDirectory)+"<br>");

    // Get all the files from the absolute path of 'MyControl';
    // using TemplateSourceDirectory which gives the virtual Directory.
        string [] myFiles=
        Directory.GetFiles(MapPathSecure(TemplateSourceDirectory));
        output.Write("The files in this Directory are <br>");

         // List all the files.
         for (int i=0;i<myFiles.Length;i++)
            output.Write(myFiles[i]+"<br>");
' An HttpException occurs if the server control does not,;
' have permissions to read the resulting mapped file.
output.Write("The Actual Path of the virtual directory : " & _
            MapPathSecure(TemplateSourceDirectory) & "<br>")

' Get all the files from the absolute path of 'MyControl';
' using TemplateSourceDirectory which gives the virtual Directory.
Dim myFiles As String() = Directory.GetFiles(MapPathSecure(TemplateSourceDirectory))
output.Write("The files in this Directory are <br>")

' List all the files.
Dim i As Integer
For i = 0 To myFiles.Length - 1
   output.Write(myFiles(i) & "<br>")
Next i

Keterangan

Properti TemplateSourceDirectory menentukan jalur ke halaman atau kontrol pengguna yang berisi kontrol saat ini. Misalnya, jika halaman Web berada di http://www.contoso.com/application/subdirectory, TemplateSourceDirectory properti mengembalikan "aplikasi/subdirektori".

Untuk mengembalikan jalur virtual relatif aplikasi ("~/subdirektori"), gunakan AppRelativeTemplateSourceDirectory properti .

Berlaku untuk

Lihat juga