none
using Directory Services in sandboxed Solution

Všechny reakce

  • Hi Anwar,

    For this issue, it would be better if you provide you code snippet to interact with directory service, and the error message you met when you testing it.

    Also, here is an article about how to get user data from active directory, you can refer to it for more information about how to interact with it:
    http://www.codeproject.com/Articles/6778/How-to-get-User-Data-from-the-Active-Directory

    Thanks,
    Qiao


    Qiao Wei

    TechNet Community Support

    14. června 2012 6:36
  • What's the error? I haven't checked the exact details, but it's possible that CAS restrictions of sandboxed solutions prevent access to AD (ie, access to SQL Server databases is forbidden, so I wouldn't be surprised). Instead, it'll be easier to wrap the AD functionality in a WCF service. You can call WCF service methods without problems within the sandbox.

    Check my article at http://sharepointdragons.com/2011/10/07/parallel-programming-in-sharepoint-2010-the-back-to-the-future-pattern/ for help about creating WCF services in a SharePoint environment.


    Kind regards,
    Margriet Bruggeman

    Lois & Clark IT Services
    web site: http://www.loisandclark.eu
    blog: http://www.sharepointdragons.com


    14. června 2012 6:47
  • hi,

    This Code i written in Sand Boxed Work Flow.

    public Hashtable GetUsers(SPUserCodeWorkflowContext context)
            {
                Hashtable results = new Hashtable();
                results.Add("Except", string.Empty); 

                try
                {
                    using (DirectoryEntry de = new DirectoryEntry("LDAP://XXX.com/CN=Users,dc=XX,dc=com"))
                    {

                        DirectorySearcher search = new DirectorySearcher(de);
                        search.Filter = "(&(objectClass=user))";
                        SearchResultCollection searchresults = search.FindAll();

                        if (searchresults.Count > 0)
                        {
                            foreach (SearchResult result in searchresults)
                            {
                                using (SPSite site = new SPSite(context.CurrentWebUrl))
                                {
                                    using (SPWeb web = site.OpenWeb())
                                    {
                                        try
                                        {
                                            web.AllowUnsafeUpdates = true;
                                            SPListItemCollection listItems = web.Lists["ManageAdmin"].Items;
                                            SPListItem item = listItems.Add();
                                            ResultPropertyValueCollection sAMValuesCollection = result.Properties["samAccountName"];
                                            ResultPropertyValueCollection DisplaynameCollection = result.Properties["displayName"];
                                            foreach (object value in sAMValuesCollection)
                                            {
                                                item["UserName"] = value.ToString();
                                            }
                                            foreach (object value in DisplaynameCollection)
                                            {
                                                item["DisplayName"] = value.ToString();
                                            }
                                            item.Update();
                                        }
                                        catch (Exception)
                                        {

                                            throw;
                                        }
                                        finally
                                        {
                                            web.AllowUnsafeUpdates = false;
                                        }
                                        
                                    }
                                }
                            }

                        }
                    }
                }
                catch (Exception ex)
                {
                    results["Except"] = ex.ToString();
                }
                results["Except"]="Success"; 
                return (results);
            }


    Anwar


    14. června 2012 7:23
  • Anwar,

    I don't see any issues with your code. Instead ask your AD administrator to give the "Administrator" privilege to your account in the AD itself to see the result.

    Sometime before,I have created to WebPart to add the user to AD .Later I used to pass my login/password in AD Class.Lastly I managed to run the webpart successfully.


    Murugesa Pandian.,MCTS|App.Devleopment|Configure

    14. června 2012 8:31
  • Hi anybody,

    is it possible that this isn't possible in any way, because it's a sandbox?

    Regards,

    Roman


    Roman Pawlig MCSD.Net MCDBA SQL Server

    29. prosince 2012 17:29
  • It's always possible to do it in any way, since you can always call a web service or SharePoint proxy service.

    Kind regards,
    Margriet Bruggeman

    Lois & Clark IT Services
    web site: http://www.loisandclark.eu
    blog: http://www.sharepointdragons.com

    30. prosince 2012 10:05