Durante la realizzazione di una web part ho avuto la necessità di ottenere e visualizzare lo stato OCS dell’utente.
Per poter ottenere questo dato bisogna far riferimento al UserProfileValueCollection.
Le user properties potete trovarle da Central Administration andato a controllare le proprietà del servizio User Profile:
![userproperties1 userproperties1](http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/SalvoDiFazio/Windows-Live-Writer/Web-Part-per-Sharepoint-che-visualizza-l_9568/userproperties1_thumb.jpg)
Quella utile per ricavare i dati OSC è la proprietà WorkEmail (di default in Sharepoint inglese è chiamata così).
Innanzitutto allora dichiariamo l’html per l’immagine (trovato in giro per il web)
const string PRESENCEPAWN = @"<img border=""0"" height=""20"" width=""20"" src=""_layouts/images/imnhdr.gif"" onload=""IMNRC('{0}')"" ShowOfflinePawn=""1"" id=""{0}"" />";
IMRC è una funzione Javascript, è possibile trovarla in /_layouts/1033/owsbrows.js
Utilizzando l’istanza di UserProfile che ci interessa otteniamo un metodo del tipo:
private static string GetPropValue(UserProfile p)
{
if (p[PropertyConstants.WorkEmail] != null &&
p[PropertyConstants.WorkEmail].Value != null)
{
return p[PropertyConstants.WorkEmail].Value.ToString();
}
return string.Empty;
}
E conludiamo costruendo la stringa html corretta in questa maniera:
string imgPawn = string.Format(PRESENCEPAWN, emailStr);
adesso abbiamo l’html necessario per ottenere lo staus di ocs del nostro utente ![Smile](http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/SalvoDiFazio/Windows-Live-Writer/Web-Part-per-Sharepoint-che-visualizza-l_9568/wlEmoticon-smile_2.png)
Rebitting Tags:
Sharepoint|
Tip|
100|
OCS
posted @ lunedì 14 febbraio 2011 15:00