Acceso al valor de propiedad de perfil de usuario personalizado
-
16-10-2019 - |
Pregunta
Con el código a continuación, puedo obtener acceso a una propiedad de perfil personalizada que creé ("calificaciones"). De alguna manera, no obtengo cómo obtener acceso a la información almacenada para el campo de propiedad personalizada.
using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.Security;
using Microsoft.SharePoint.Portal;
using Microsoft.Office.Server;
using Microsoft.Office.Server.UserProfiles;
using System.Diagnostics;
namespace CV.CV
{
[ToolboxItemAttribute(false)]
public class CV : WebPart
{
Property propQualifications = null;
string strQualifications = "";
protected override void OnPreRender(EventArgs e)
{
var test = GetUserProperties();
}
public Microsoft.Office.Server.UserProfiles.PropertyCollection GetUserProperties()
{
Microsoft.Office.Server.UserProfiles.PropertyCollection oPropertyCollection = null;
System.Security.PermissionSet ps = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.Unrestricted);
ps.Assert();
Microsoft.SharePoint.SPServiceContext serviceContext = Microsoft.SharePoint.SPServiceContext.Current;
Microsoft.Office.Server.UserProfiles.UserProfileManager upm = new Microsoft.Office.Server.UserProfiles.UserProfileManager(serviceContext);
oPropertyCollection = upm.PropertiesWithSection;
propQualifications = oPropertyCollection.GetPropertyByName("Qualifications");
strQualifications = propQualifications.ToString();
System.Security.CodeAccessPermission.RevertAssert();
return oPropertyCollection;
}
}
}
Solución
Debe obtener un objeto de perfil de usuario y una vez que tenga el objeto, puede acceder a las propiedades del perfil, incluidas las personalizadas. Por ejemplo:
UserProfileManager upm = new UserProfileManager(SPServiceContext.GetContext(site));
UserProfile p = upm.GetUserProfile("accountname");
object value = p["propertyname"][0];
Licenciado bajo: CC-BY-SA con atribución
No afiliado a sharepoint.stackexchange