public bool DeleteRecycleOu(Guid transactionid, AdminInfo admin, string recycleOuPath, out ErrorCodeInfo error) { bool result = false; error = new ErrorCodeInfo(); string message = string.Empty; string paramstr = string.Empty; paramstr += $"userID:{admin.UserID}"; paramstr += $"||UserAccount:{admin.UserAccount}"; paramstr += $"||recycleOuPath:{recycleOuPath}"; DirectoryEntry ouRecycleEntry = new DirectoryEntry(); try { do { CommonProvider commonProvider = new CommonProvider(); if (!commonProvider.GetADEntryByPath(recycleOuPath, out ouRecycleEntry, out message)) { LoggerHelper.Error("OuProvider调用DeleteRecycleOu异常", paramstr, message, transactionid); break; } List <DirectoryEntry> EntryList = new List <DirectoryEntry>(); if (!commonProvider.SearchEntryData(ouRecycleEntry.Path, SearchType.All, out EntryList, out message)) { LoggerHelper.Error("OuProvider调用DeleteRecycleOu异常", paramstr, message, transactionid); result = false; break; } if (EntryList.Count > 0) { break; } else { ouRecycleEntry.DeleteTree(); ouRecycleEntry.CommitChanges(); ouRecycleEntry.Close(); } result = true; } while (false); } catch (Exception ex) { error.Code = ErrorCode.Exception; LoggerHelper.Error("OuProvider调用DeleteRecycleOu异常", paramstr, ex.ToString(), transactionid); result = false; } finally { if (ouRecycleEntry != null) { ouRecycleEntry.Close(); } } return(result); }