小编pso*_*han的帖子

如何使用xml Document在现有元素下添加新元素

我有一个名为"Dispute"的元素,并希望在元素下面添加新的元素名称"Records".
例如:当前的XML采用这种格式

<NonFuel>
    <Desc>Non-Fuel</Desc>
    <Description>
    </Description>
    <Quantity/>
    <Amount/>
    <Additional/>
    <Dispute>0</Dispute>
</NonFuel>
Run Code Online (Sandbox Code Playgroud)

需要添加有争议的新元素.

<NonFuel>
    <Desc>Non-Fuel</Desc>
    <Description>
    </Description>
    <Quantity/>
    <Amount/>
    <Additional/>
    <Dispute>0</Dispute>
    <Records>01920</Records>
</NonFuel>
Run Code Online (Sandbox Code Playgroud)

更新的代码:
尝试执行以下代码但收到错误"参考节点不是此节点的子节点":

XmlDocument xmlDoc=new XmlDocument()
xmlDoc.LoadXml(recordDetails);
XmlNodeList disputes = xmlDoc.GetElementsByTagName(disputeTagName);
XmlNode root = xmlDoc.DocumentElement;
foreach (XmlNode disputeTag in disputes)
{
    XmlElement xmlRecordNo = xmlDoc.CreateElement("RecordNo");
    xmlRecordNo.InnerText = Guid.NewGuid().ToString();
    root.InsertAfter(xmlRecordNo, disputeTag);
}
Run Code Online (Sandbox Code Playgroud)

xml c#-4.0

6
推荐指数
2
解决办法
5万
查看次数

如何使用LDAP从Active Directory获取所有用户的详细信息

我需要使用LDAP从Active Directory获取所有用户的详细信息.以下代码确实提供Samaccountname了"管理员",但不是每个用户的详细信息,并且列表中没有找到邮件ID.请帮助.

string dominName = ConfigurationManager.AppSettings["DominName"].ToString();
string ldapPath = ConfigurationManager.AppSettings["ldapPath"].ToString();
if (!String.IsNullOrEmpty(dominName) && !String.IsNullOrEmpty(ldapPath))
{
    DirectoryEntry entry = new DirectoryEntry(ldapPath, txtUsername.Text.ToString().Trim(), txtPassword.Text.ToString().Trim());
    try
    {
        Object obj = entry.NativeObject;
        DirectorySearcher search = new DirectorySearcher(entry);
        search.Filter = "(&(objectClass=user)(objectCategory=person))";
        search.PropertiesToLoad.Add("samaccountname");
        search.PropertiesToLoad.Add("mail");
        search.PropertiesToLoad.Add("usergroup");
        search.PropertiesToLoad.Add("displayname");//first name

        foreach (System.DirectoryServices.SearchResult resEnt in search.FindAll())
        {    
            System.DirectoryServices.DirectoryEntry de = resEnt.GetDirectoryEntry();
            if (de.Properties["sAMAccountName"].Value != null && de.Properties["userAccountControl"].Value!=null)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("Name = " + de.Properties["sAMAccountName"].Value.ToString());
                sb.AppendLine("Email = " + de.Properties["Mail"].Value.ToString());
            }
        }
Run Code Online (Sandbox Code Playgroud)

找到解决方案

这是我的代码:

var …
Run Code Online (Sandbox Code Playgroud)

c# asp.net ldap

3
推荐指数
2
解决办法
4万
查看次数

标签 统计

asp.net ×1

c# ×1

c#-4.0 ×1

ldap ×1

xml ×1