Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7608657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:58:25+00:00 2026-05-31T00:58:25+00:00

Ok so i’m trying to pull a user from active directory into a DirectoryUser

  • 0

Ok so i’m trying to pull a user from active directory into a DirectoryUser object and if I type it like this, it works fine:

DirectoryEntry user = new DirectoryEntry(@"LDAP://CN=Name, OU=Department, OU=Group, DC=Domain1, DC=Domain2");
user.Properties["thumbnailPhoto"].Clear();

But I need the values to be able to be changed, so I tried a formatted string:

string ldap = string.Format("LDAP://CN={0}, OU={1}, OU={2}, DC={3}, DC={4}", cn, group, ou, domain1, domain2);
DirectoryEntry user = new DirectoryEntry(ldap);
user.Properties["thumbnailPhoto"].Clear();

But this causes an error “There is no such object on the server”

The constructor takes a string, and I pass in the same exact values that i was using when i wrote it literally, why is it working one way an not the other?!

EDIT:
I just wanted to add that I double checked in several different ways to verify that the built string was coming out identical to the hard coded string and it is. I ran through debugger and checked the user.path value to verify that the strings were being stored exactly the same. Everything so far is identical, but one works and the other doesn’t!

UPDATE:
I noticed that if I hard code directly to a string variable:

string ldap = @"Jeremy Stafford", "IT", "QGT", "QGT", "Local";
DirectoryEntry user = new DirectoryEntry(ldap);

This works just fine. This leads me to believe that there may be a problem with the string “type”. Maybe if I could convert the built string back to a primitive string (or rather a value type versus the reference type), it would work? But I have no Idea how to do that. Any ideas?

UPDATE:
I ran a semantic test. Here is the code I used:

string ldapFormatted = string.Format("LDAP://CN={0}, OU={1}, OU={2}, DC={3}, DC={4}", cn, group, ou, domain1, domain2);                
                var ldapHardCoded = @"LDAP://CN=Jeremy Stafford, OU=IT, OU=QGT, DC=QGT, DC=Local";
                string message;

                if (ldapFormatted.Equals(ldapHardCoded))
                {
                    message = "They're the same value\n";
                }
                else
                {
                    message = "Strings are not the same value\n";
                }

                if (ldapFormatted.GetType() == ldapHardCoded.GetType())
                {
                   message += "They are the same type";
                }
                else
                {
                    message += "They are not the same type";
                }
                message += "\n\n" + ldapFormatted + "\n" + ldapHardCoded;
                MessageBox.Show(message);

And here was the result:

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T00:58:27+00:00Added an answer on May 31, 2026 at 12:58 am

    I tried your code and filled the format variables and it works for me as you can see in the screenshot.

      string cn = "Jeremy Stafford";
      String group = "IT";
      string ou = "QGT";
      String domain1 = "QGT";
      string domain2 = "Local";
      string ldapFormatted = string.Format("LDAP://CN={0}, OU={1}, OU={2}, DC={3}, DC={4}", cn, group, ou, domain1, domain2);
    
      var ldapHardCoded = @"LDAP://CN=Jeremy Stafford, OU=IT, OU=QGT, DC=QGT, DC=Local";
      string message;
    
      if (ldapFormatted.Equals(ldapHardCoded))
      {
        message = "They're the same value\n";
      }
      else
      {
        message = "Strings are not the same value\n";
      }
    
      if (ldapFormatted.GetType() == ldapHardCoded.GetType())
      {
        message += "They are the same type";
      }
      else
      {
        message += "They are not the same type";
      }
      message += "\n\n" + ldapFormatted + "\n" + ldapHardCoded;
      MessageBox.Show(message);
    

    Message

    You should really check whats in your input variables. Maybe you have some invisible chars in it. Convert your input variables into byte arrays and print out the array to get more insight what you have in there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
I have some data like this: 1 2 3 4 5 9 2 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.