Accès personnalisé Profil utilisateur Valeur de la propriété
-
16-10-2019 - |
Question
Avec le code ci-dessous, je suis en mesure d'obtenir l'accès à une propriété de profil personnalisé que je créé ( « qualifications »). D'une certaine façon je ne comprends comment accéder aux informations stockées dans le champ de propriété personnalisée ..
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;
}
}
}
La solution
Vous devez obtenir un objet de profil d'utilisateur et une fois que vous avez l'objet, vous pouvez accéder aux propriétés du profil, y compris ceux personnalisés. Par exemple:
UserProfileManager upm = new UserProfileManager(SPServiceContext.GetContext(site));
UserProfile p = upm.GetUserProfile("accountname");
object value = p["propertyname"][0];
Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange