ディレクトリ オブジェクトのプロパティの設定
ここでは、ディレクトリ オブジェクトの 1 つの値を含むプロパティの設定について説明し、そのコード例を示します。
次のメソッドを使用してプロパティ値を変更します。
- Value は、PropertyValueCollection オブジェクトのプロパティで、1 つの値を含むプロパティに新しい値を直接設定します。
- Add は、複数値プロパティに値を追加する PropertyValueCollection オブジェクトのメソッドです。複数値プロパティの詳細については、「複数値を含むプロパティ」を参照してください。
プロパティ値を設定すると、データはプロパティ キャッシュに格納されます。ディレクトリに新しいデータを書き込むには、CommitChanges メソッドを呼び出します。詳細については、「プロパティ キャッシュ」を参照してください。
次のコード例は、Value プロパティの使用方法を示しています。
Try
Dim ent As New DirectoryEntry("LDAP://Fabrikam/CN=My Username,CN=Users,DC=Fabrikam,DC=com")
ent.Properties("sn").Value = "Barr"
ent.CommitChanges()
Catch COMEx As COMException
' If a COMException is thrown, then the following code example can catch the text of the error.
' For more information about handling COM exceptions, see Handling Errors.
Console.WriteLine(COMEx.ErrorCode)
End Try
try
{
DirectoryEntry ent = new DirectoryEntry(
"LDAP://Fabrikam/CN=My Username,CN=Users,DC=Fabrikam,DC=com");
ent.Properties["sn"].Value = "Barr";
ent.CommitChanges();
}
catch (COMException COMEx)
{
// If a COMException is thrown, then the following code example can catch the text of the error.
// For more information about handling COM exceptions, see Handling Errors.
Console.WriteLine(COMEx.ErrorCode);
}
関連項目
リファレンス
System.DirectoryServices
PropertyValueCollection
DirectoryEntry
概念
ディレクトリ オブジェクト プロパティ
プロパティ キャッシュ
複数値を含むプロパティ
Send comments about this topic to Microsoft.
Copyright © 2007 by Microsoft Corporation. All rights reserved.