none
Search in AD from VSTO RRS feed

  • Question

  •  use FW 4.5 and develop Add-in for WORD 2016. In add-in I need search in AD, I use the next code :

    string ldapPath = "LDAP://OU=Ingegneria,DC=xxx,DC=xxx";
    DirectoryEntry searchRoot = GetEntry(ldapPath, adminUser, adminPassword);
    
    
    DirectorySearcher search = new DirectorySearcher(searchRoot)
    {
        SearchScope = SearchScope.Subtree,
        Filter = "(&" +
        "(objectClass=user)" +
        "(givenname=s*)" +
        "(samaccountname=*100)" +
    ")"
    };
    
    search.PropertiesToLoad.Add("distinguishedname");
    SearchResultCollection result = search.FindOne();

    Every query take about 800 miliseconds.

    BUT At the same computer , same code outside of add-in(tester) : first search take about 800 miliseconds , and after this every search take about 25 miliseonds.

    What the problem with add-in? And what can I do ?

    Monday, April 2, 2018 6:30 PM

All replies

  •  use FW 4.5 and develop Add-in for WORD 2016. In add-in I need search in AD, I use the next code :

    string ldapPath = "LDAP://OU=Ingegneria,DC=xxx,DC=xxx";
    DirectoryEntry searchRoot = GetEntry(ldapPath, adminUser, adminPassword);
    
    
    DirectorySearcher search = new DirectorySearcher(searchRoot)
    {
        SearchScope = SearchScope.Subtree,
        Filter = "(&" +
        "(objectClass=user)" +
        "(givenname=s*)" +
        "(samaccountname=*100)" +
    ")"
    };
    
    search.PropertiesToLoad.Add("distinguishedname");
    SearchResultCollection result = search.FindOne();

    Every query take about 800 miliseconds.

    BUT At the same computer , same code outside of add-in(tester) : first search take about 800 miliseconds , and after this every search take about 25 miliseonds.

    What the problem with add-in? And what can I do ?

    • Moved by CoolDadTx Wednesday, April 4, 2018 2:35 PM Office related
    • Merged by Terry Xu - MSFT Monday, April 9, 2018 6:18 AM same issue
    Monday, April 2, 2018 6:27 PM
  • Hello AhmedAbd_Iran,

    What's the result if you try to create a new thread to run the code? Will it still run the code slowly?

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, April 3, 2018 9:57 AM
  • Hello AhmedAbd_Iran,

    >>BUT At the same computer , same code outside of add-in(tester) : first search take about 800 miliseconds , and after this every search take about 25 miliseonds.

    In my knowledge, when C# code is build to native code by just-in-time compilation it could bring some optimized job like saving previous result for next executing. This operation will encounter a circumstance that first will take some time while second runs more quickly than previous. I'm not sure if you are under the same situation. If so it's more related to compiler problem and I don't have any idea about the workaround.

    Best Regards,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, April 4, 2018 10:09 AM
  • Hello,

    What's the current state of the thread? Has your original issue been resolved? If it has, I would suggest you mark the helpful reply as answer or provide your solution and mark as answer to close this thread. If not, please feel free to let us know your current issue.
    Best Regards,
    Terry

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, April 12, 2018 6:07 AM
  • Hello,

    Has your original issue been resolved? If it has, I would suggest you mark the helpful reply as answer or provide your solution and mark as answer to close this thread. If not, please feel free to let us know your current issue.

    Best Regards,

    Terry



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, April 16, 2018 4:49 AM