本文整理汇总了C#中System.DirectoryServices.DirectoryEntry.DeleteTree方法的典型用法代码示例。如果您正苦于以下问题:C# DirectoryEntry.DeleteTree方法的具体用法?C# DirectoryEntry.DeleteTree怎么用?C# DirectoryEntry.DeleteTree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.DirectoryServices.DirectoryEntry
的用法示例。
在下文中一共展示了DirectoryEntry.DeleteTree方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Convert
public override void Convert(ObjectModifyType modifyType, IOguObject srcObject, DirectoryEntry targetObject, string context)
{
ADHelper adHelper = SynchronizeContext.Current.ADHelper;
if (SynchronizeContext.Current.RecycleBinOU.IsNotEmpty())
{
ProcessDeleteEntry(modifyType, srcObject, targetObject, context);
//ChangeEntryNameToFullPath(targetObject);
using (DirectoryEntry parentEntry = adHelper.NewEntry(SynchronizeContext.Current.RecycleBinOU))
{
DoTheMove(targetObject, parentEntry, srcObject);
}
}
else
{
targetObject.DeleteTree();
}
}
示例2: DirectoryEntry_Properties2
public void DirectoryEntry_Properties2()
{
// delete entry, create a new one (the same) and access properties of the old object
string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
de = new DirectoryEntry(barakTsabariDN,
configuration.Username,
configuration.Password,
configuration.AuthenticationType);
// cause to properties loading
Assert.AreEqual(de.Properties.Count,6);
Assert.AreEqual(((PropertyValueCollection)de.Properties["sn"]).Value,"Tsabari");
// delete entry
de.DeleteTree();
// the local property chache is still accessible
Assert.AreEqual(de.Properties.Count,6);
Assert.AreEqual(((PropertyValueCollection)de.Properties["sn"]).Value,"Tsabari");
de.CommitChanges();
// the local property chache is still accessible
((PropertyValueCollection)de.Properties["sn"]).Value = "Barbari";
// create the entry back again
using (DirectoryEntry ouHumanResources = new DirectoryEntry( configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
configuration.Username,
configuration.Password,
configuration.AuthenticationType)){
using (DirectoryEntry cnBarakTsabari = ouHumanResources.Children.Add("cn=Barak Tsabari","Class")){
((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("person");
((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("organizationalPerson");
cnBarakTsabari.Properties["cn"].Value = "Barak Tsabari";
cnBarakTsabari.Properties["facsimileTelephoneNumber"].Value = "+1 906 777 8853";
((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("Human Resources");
((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("People");
cnBarakTsabari.Properties["sn"].Value = "Tsabari";
cnBarakTsabari.Properties["telephoneNumber"].Value = "+1 906 777 8854";
cnBarakTsabari.CommitChanges();
}
}
// the local property chache is still accessible
Assert.AreEqual(((PropertyValueCollection)de.Properties["sn"]).Value,"Barbari");
// Refresh from server
de.RefreshCache();
// ensure the properties of an entry are still accessible through the old object
Assert.AreEqual(((PropertyValueCollection)de.Properties["sn"]).Value,"Tsabari");
}
示例3: DirectoryEntry_Properties1
public void DirectoryEntry_Properties1()
{
de = new DirectoryEntry(configuration.ConnectionString);
Assert.AreEqual(de.Properties.Count,3);
Assert.AreEqual(((PropertyValueCollection)de.Properties["dc"]).Value,"example");
Assert.AreEqual(((PropertyValueCollection)de.Properties["description"]).Value,null);
de = new DirectoryEntry(configuration.ConnectionString,
configuration.Username,
configuration.Password,
configuration.AuthenticationType);
Assert.AreEqual(de.Properties.Count,3);
Assert.AreEqual(((PropertyValueCollection)de.Properties["dc"]).Value,"example");
Assert.AreEqual(((PropertyValueCollection)de.Properties["description"]).Value,null);
// ensure that properties are not accessible after removing an entry from the server
string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
de = new DirectoryEntry(barakTsabariDN,
configuration.Username,
configuration.Password,
configuration.AuthenticationType);
de.DeleteTree();
try {
int i = de.Properties.Count;
Assert.Fail("Properties should not be accessible after deleting an entry from the server");
}
catch(AssertionException ae) {
throw ae;
}
catch(Exception e) {
// supress exception
}
try {
string s = (string)((PropertyValueCollection)de.Properties["dc"]).Value;
Assert.Fail("Properties should not be accessible after deleting an entry from the server");
}
catch(AssertionException ae) {
throw ae;
}
catch(Exception e) {
// supress exception
}
}
示例4: DeleteSiteVirtual
/// <summary>
/// 删除网站或虚拟目录
/// </summary>
/// <param name="virPath">地址 1/root/bbsmax</param>
/// <returns></returns>
public static void DeleteSiteVirtual(string path)
{
DirectoryEntry deDir = new DirectoryEntry(path);
try
{
deDir.DeleteTree();
}
catch (Exception ex)
{
throw new Exception("删除失败:" + ex.Message);
}
finally
{
deDir.Close();
}
}
示例5: DeleteOU
/// <summary>
/// 删除OU
/// </summary>
/// <param name="ouEntry"></param>
/// <param name="newOUName"></param>
/// <returns></returns>
public static bool DeleteOU(DirectoryEntry ouEntry)
{
//try
//{
//DirectoryEntry OUParent = ouEntry.Parent;
ouEntry.DeleteTree();
//OUParent.Children.Remove(ouEntry);
ouEntry.CommitChanges();
//OUParent.CommitChanges();
return true;
//}
//catch (Exception ex)
//{
// LogFactory.ExceptionLog.Error(ex);
// return false;
//}
}
示例6: RemoveVirtualDirectory
private void RemoveVirtualDirectory(ActionEntry entry)
{
string fullPath, parentDir, dirName;
GetSelectedDirectoryPath( out fullPath, out parentDir, out dirName );
entry.LogLine( "Removing directory entry '" + fullPath + "'" );
using( var directoryEntry = new DirectoryEntry(fullPath) )
{
directoryEntry.DeleteTree();
}
}
示例7: DeleteOU
/// <summary>
/// Deletes an OU from Active Directory
/// </summary>
/// <param name="distinguishedName"></param>
public void DeleteOU(string distinguishedName)
{
DirectoryEntry de = null;
try
{
this.logger.Debug("Deleting organizational unit " + distinguishedName);
de = new DirectoryEntry("LDAP://" + this.domainController + "/" + distinguishedName, this.username, this.password);
de.DeleteTree();
}
catch (Exception)
{
throw;
}
finally
{
if (de != null)
de.Dispose();
}
}
示例8: DeleteTree_DFS
private void DeleteTree_DFS(DirectoryEntry de)
{
foreach(DirectoryEntry child in de.Children) {
DeleteTree_DFS(child);
}
de.DeleteTree();
de.CommitChanges();
}
示例9: DeleteOUAll
/// <summary>
/// Deletes the OU and everything in the OU.
/// **** DESTRUCTIVE!!! ****
/// </summary>
/// <param name="distinguishedName"></param>
public void DeleteOUAll(string distinguishedName)
{
DirectoryEntry de = null;
try
{
de = new DirectoryEntry("LDAP://" + this.domainController + "/" + distinguishedName, this.username, this.password);
// Delete the OU
de.DeleteTree();
}
catch (Exception)
{
throw;
}
finally
{
if (de != null)
de.Dispose();
}
}
示例10: DeleteEntry
public void DeleteEntry(DirectoryEntry dirEntry)
{
dirEntry.DeleteTree();
dirEntry.CommitChanges();
}
示例11: DeleteSite
public static void DeleteSite(string serverName, int siteID)
{
DirectoryEntry site = new DirectoryEntry(string.Format(MetabaseSiteFormat, serverName, siteID.ToString()));
site.DeleteTree();
site.CommitChanges();
}
示例12: DetTree
/// <summary>
/// 删除对象
/// </summary>
/// <param name="path">对象路径</param>
public static void DetTree(string path)
{
try
{
DirectoryEntry ent = new DirectoryEntry(path, ADUser, ADPassword);
ent.DeleteTree();
}
catch (Exception e)
{
throw e;
}
}
示例13: DeleteUserAccount
public bool DeleteUserAccount(string FQDN, LogFile log)
{
try
{
FQDN = "LDAP://" + FQDN;
DirectoryEntry ent = new DirectoryEntry(FQDN);
ent.DeleteTree();
ent.Close();
ent.Dispose();
log.addTrn("deleted user account |" + FQDN, "Transaction");
return true;
}
catch (System.DirectoryServices.DirectoryServicesCOMException E)
{
log.addTrn(E.Message.ToString() + " error deleting user " + FQDN, "Error");
return false;
}
}
示例14: DeleteOU
public void DeleteOU(string ouPath, string name, LogFile log)
{
try
{
//needs parent OU present to work
if (!DirectoryEntry.Exists("LDAP://OU=" + name + "," + ouPath))
{
DirectoryEntry entry = new DirectoryEntry("LDAP://" + ouPath);
entry.DeleteTree();
entry.Close();
entry.Dispose();
log.addTrn("deleting ou | LDAP://OU=" + name + "," + ouPath + " does not exists", "Transaction");
}
else
{
log.addTrn("error deleting ou LDAP://OU=" + name + "," + ouPath + " does not exists", "Warning");
}
}
catch (Exception ex)
{
log.addTrn(ex.Message.ToString() + " error deleting ou LDAP://OU=" + name + "," + ouPath + "\n" + ex.StackTrace.ToString(), "Error");
}
}
示例15: DirectoryEntry_DeleteTree
public void DirectoryEntry_DeleteTree()
{
string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
Assert.IsTrue(DirectoryEntry.Exists(barakTsabariDN));
de = new DirectoryEntry(barakTsabariDN,
configuration.Username,
configuration.Password,
configuration.AuthenticationType);
// no properties changed
de.DeleteTree();
de.CommitChanges();
Assert.IsFalse(DirectoryEntry.Exists(barakTsabariDN));
string johnSmithDN = configuration.ServerRoot + "cn=John Smith,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
Assert.IsTrue(DirectoryEntry.Exists(johnSmithDN));
de = new DirectoryEntry(johnSmithDN,
configuration.Username,
configuration.Password,
configuration.AuthenticationType);
de.Properties["telephoneNumber"].Value = "+972 3 9999999";
// some properties changed
de.DeleteTree();
try {
de.CommitChanges();
Assert.Fail("Object " + johnSmithDN + " was not deleted from server");
}
catch(AssertionException ae) {
throw ae;
}
catch(Exception e) {
// do nothing
}
}