前回の記事では、Propertiesプロパティに”FullName”を指定して、ログオン名からフルネームを取得する例を紹介しました。
では、Propertiesプロパティには、どのような値を指定することが可能なのでしょうか?
Propertiesプロパティに指定可能な値は、Propertiesプロパティが持つ、PropertyNamesプロパティを参照することで取得することが可能です。
DirectoryEntryコンポーネントにパスを設定した後、For Each(C#ならforeach)で、PropertyNamesを取り出します。
下記は、Propertiesプロパティに指定可能な値を取得する例です。
Path欄にWinNTプロバイダパスやLDAPパスを指定し、[Propertiesプロパティに指定可能な値]ボタンをクリックすると、指定可能な値の一覧が表示されます。
VBの例
' [Propertiesプロパティに指定可能な値を取得]ボタンクリック時の処理
Private Sub btnGetPropertiesValue_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetPropertiesValue.Click
'DirectoryEntryコントロールのPathプロパティにパスを設定
DirectoryEntry1.Path = txtPath.Text
'リストボックスの初期化
ListBox1.Items.Clear()
'★★★Propertiesプロパティ指定可能な値を取得★★★
For Each p In DirectoryEntry1.Properties.PropertyNames
ListBox1.Items.Add(p.ToString())
Next
End Sub
C#の例
// [Propertiesプロパティに指定可能な値を取得]ボタンクリック時の処理
private void btnGetPropertiesValue_Click(object sender, EventArgs e)
{
// DirectoryEntryコントロールのPathプロパティにパスを設定
directoryEntry1.Path = txtPath.Text;
// リストボックスの初期化
listBox1.Items.Clear();
// ★★★Propertiesプロパティ指定可能な値を取得★★★
foreach (var p in directoryEntry1.Properties.PropertyNames)
listBox1.Items.Add(p.ToString());
}
Please follow and like us:


コメント