Control.TemplateSourceDirectory Свойство
Определение
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Возвращает виртуальный Page каталог или UserControl содержащий текущий серверный элемент управления.
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
Значение свойства
Виртуальный каталог страницы или пользовательского элемента управления, содержащий серверный элемент управления.
- Атрибуты
Примеры
В следующем примере свойство используется TemplateSourceDirectory дважды. При первом вызове метода он используется Control.MapPathSecure для получения пути к каталогу, в котором находится элемент управления. Во второй раз вызывается метод для получения списка всех файлов, содержащихся в Directory.GetFiles этом каталоге.
// 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
Комментарии
Свойство TemplateSourceDirectory задает путь к странице или пользовательскому элементу управления, который содержит текущий элемент управления. Например, если веб-страница находится на http://www.contoso.com/application/subdirectory, TemplateSourceDirectory свойство возвращает значение application/subdirectory.
Чтобы вернуть относительный к приложению виртуальный путь ("~/subdirectory"), используйте AppRelativeTemplateSourceDirectory свойство.