سؤال

أحاول إنشاء صالة جديدة في صفحة ASP جديدة على موقع SharePoint الخاص بي.

لذلك أحتاج إلى حقل يمكنه البحث في جميع المستخدمين وحدد واحد.

رأيت في العديد من المنتديات مفادها أن أفضل الضوابط هي الشعب أو الشعبية.

الآن يجب أن أحصل على القيمة من عنصر التحكم وأرادها إلى قائمة ...

هو جافا سكريبت الطريقة الوحيدة للقيام بذلك؟لا أستطيع أن أرى أي خيارات جيدة في الخصائص ...


في رمز ASPX الخاص بي، حاولت وضع عنصر تحكم UperField ولكن الصفحة لا تظهر لها ... نفس الشيء بالنسبة إلى playpickerdialog

إليك الرمز الخاص بي: giveacodicetagpre.

وهنا رمز وراء giveacodicetagpre.

GetUser() فقط إرجاع SPUser ... يجب أن تعمل ... أو لا ...

هل كانت مفيدة؟

المحلول

This is what I have been using to get an SPFieldUserValue from the resolved users and groups in a PeopleEditor control.

public static SPFieldUserValue GetPeopleFromPickerControl(PeopleEditor people, SPWeb web)
{
    SPFieldUserValue value = null;
    if (people.ResolvedEntities.Count > 0)
    {
        for (int i = 0; i < people.ResolvedEntities.Count; i++)
        {
            try
            {
                PickerEntity user = (PickerEntity)people.ResolvedEntities[i];

                switch ((string)user.EntityData["PrincipalType"])
                {
                    case "User":
                        SPUser webUser = web.EnsureUser(user.Key);
                        value = new SPFieldUserValue(web, webUser.ID, webUser.Name);
                        break;

                    case "SharePointGroup":
                        SPGroup siteGroup = web.SiteGroups[user.EntityData["AccountName"].ToString()];
                        value = new SPFieldUserValue(web, siteGroup.ID, siteGroup.Name);
                        break;
                    default:
                        SPUser spUser = web.EnsureUser(people.Accounts[i].ToString());
                        value = new SPFieldUserValue(web, spUser.ID, spUser.Name);
                        break;
                }
            }
            catch (Exception ex)
            {
                // log or do something
                SPUser spUser = web.EnsureUser(people.Accounts[i].ToString());
                value = new SPFieldUserValue(web, spUser.ID, spUser.Name);
            }
        }
    }
    return value;
}

نصائح أخرى

In the code behind of your aspx use can use the following code:

foreach (PickerEntity resolvedEntity in peopleEditor.ResolvedEntities)
{
    SPPrincipalType principalType = (SPPrincipalType)Enum.Parse(typeof(SPPrincipalType), resolvedEntity.EntityData["PrincipalType"].ToString());
    if (principalType == SPPrincipalType.User || principalType == SPPrincipalType.SecurityGroup)
    {
        string loginName = resolvedEntity.Key;
        //get the user form web.SiteUsers
    }
    else if (principalType == SPPrincipalType.SharePointGroup)
    {
        string groupName = resolvedEntity.Key;
        //get the group here from web.SiteGroups
    }
}

I would revise it like this, where pectrl is the PeopleEditor. Note: This assumes you add a MultiSelect="false" attribute on your PeopleEditor, though theoretically you should be able to use a loop like in Sean's example to get them all, but you would need to return a collection, not just SPUser or SPFieldUserValue to do that:

public static SPUser GetUserFromPickerControl()
{
    SPUser user = null;
    if (pectrl.ResolvedEntities.Count > 0)
    {
        try
        {
            PickerEntity pe = (PickerEntity)pectrl.ResolvedEntities[0];
            SPFieldUserValue userValue = new SPFieldUserValue(web, Convert.ToInt32(pe.EntityData["SPUserID"]), pe.Key);
            user = userValue.User;
        }
        catch (Exception ex)
        {
            // log or do something
        }
    }

    return user;
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى sharepoint.stackexchange
scroll top