Microsoft Lync configuration with SharePoint server & Site
Steps:
JavaScript:
<script type="text/javascript">
function getGrid() {
var grid = document.getElementById('<%=GridView1.ClientID%>');
var div = document.getElementById('SIPDIV');
var name = "";
var namearray = new Array();
if (grid.rows.length > 0) {
for (i = 0; i <= grid.rows.length - 1; i++) {
var cell = grid.rows[i].cells[0];
for (j = 0; j < cell.childNodes.length; j++) {
if (grid.rows[i].cells[0].childNodes[j].type =='checkbox') {
var cellPivot = false;
cellPivot = grid.rows[i].cells[0].childNodes[j].checked;
if (cellPivot == true) {
//name += grid.rows[i].cells[1].innerHTML;
if (name == "") {
name = grid.rows[i].cells[1].childNodes[1].innerText;
}
else{
name += "," + grid.rows[i].cells[1].childNodes[1].innerText;
}
}
}
}
}
var IDQuery = SplitValues(name);
window.open(IDQuery,"Lync");
}
}
var emailid = "";
var sipId = "";
function SplitValues(emailid) {
var Emailarr = new Array();
Emailarr = emailid.split(",");
for (i = 0; i < Emailarr.length; i++)
{
if (i == 0)
{
sipId = "im:<sip:" + Emailarr[i] + ">";
}
else
{
sipId = sipId + "<sip:" + Emailarr[i] + ">";
}
}
return sipId;
}
</script>
aspx Html Code:
<asp:GridView ID="GridView1" runat="server" EnableModelValidation="True"
onrowdatabound="GridView1_RowDataBound">
<HeaderStyle BackColor="#099BC4" ForeColor="White" Wrap="True" />
<Columns>
<asp:TemplateField ShowHeader="true" HeaderText ="">
<HeaderTemplate>
<asp:CheckBox runat="server" ID="CheckBox2" Checked="false"/>
</HeaderTemplate>
<ItemTemplate >
<asp:CheckBox ID="CheckBox1" runat="server" Checked="false" >
</asp:CheckBox>
</ItemTemplate>
<ItemStyle Width="30px" BackColor="AliceBlue" />
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Button ID="Button1" runat="server" Text="Start Conference"
onClientClick="getGrid()"/>
C# Code:
SPFieldUserValueCollection fvc = new SPFieldUserValueCollection();
DataTable dt = new DataTable();
DataRow dr;
protected void Page_Load(object sender, EventArgs e)
{
try
{
dt.Columns.Add("Users");
SPWeb web;
web = SPContext.Current.Web;
SPGroupCollection collGroups = web.Groups;
SPList list = web.Lists["UserGroup"];
SPFieldUserValueCollection fvc = new SPFieldUserValueCollection();
foreach (SPListItem item in list.Items)
{
string fieldValue = item["UserName"].ToString();
Getusers(fieldValue);
}
}
catch (Exception ex)
{
Label1.Text = ex.Message;
Label1.Visible = true;
}
}
void Getusers(string fieldValue)
{
SPWeb web;
web = SPContext.Current.Web;
fvc = new SPFieldUserValueCollection(web, fieldValue);
foreach (SPFieldUserValue userValue in fvc)
{
SPUser user = userValue.User;
}
//string Html = string.Empty;
GetPresenceHTMLFromUVC(SPContext.Current.Site, fvc);
// Label1.Text += Html;
}
public void GetPresenceHTMLFromUVC(SPSite thisSite, SPFieldUserValueCollection uvc)
{
StringBuilder html = new StringBuilder("");
using (SPWeb thisWeb = thisSite.RootWeb)
{
foreach (SPFieldUserValue uv in uvc)
{
string sipAddress = "";
//Get the sip address if it exists
SPListItem user = thisWeb.SiteUserInfoList.GetItemById(uv.LookupId);
if (user["SipAddress"] != null)
{
sipAddress = user["SipAddress"].ToString();
}
//construct the html for this user and add to overall html
html.Append(String.Concat(
"<div id\"PresenceLink"
, sipAddress
, "\">"
, "<img border=\"0\" height=\"12\" src=\"/_layouts/images/imnhdr.gif\" onload=\"IMNRC('"
, sipAddress
, "')\" ShowOfflinePawn=\"1\" style=\"padding-right: 3px;\" id=\"PresencePawn"
, sipAddress
, "\" alt=\"presence pawn for "
, sipAddress
, "\"/>"
, "<a href=\""
, thisWeb.Url
, "/_layouts/userdisp.aspx?ID="
, uv.LookupId
, "\" id=\"ProfileLink"
, sipAddress
, "\">"
, uv.User.Name
, "</a></div><div id='SIPDIV' style='display:none'>"+sipAddress+"</div>"
//, "</a></div><div id='"+sipAddress+"' style='display:none'></div>"
));
dr = dt.NewRow();
dr["Users"] = html;
dt.Rows.Add(dr);
//Bind data into gridview
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
foreach (TableCell cell in e.Row.Cells)
{
if (e.Row.Cells.GetCellIndex (cell)!=0)
{
cell.Text = HttpContext.Current.Server.HtmlDecode(cell.Text);
}
}
}
OutPut:
Steps:
- Install the lync server in SharePoint Server with the help this video Installing the Lync Server
- Update the User profile For Every User With Sip address,Email Id.
- Create sandbox solution to Show Group users in Grid view.
- Select some users in Grid View and Start Group Conversation Using Lync
JavaScript:
<script type="text/javascript">
function getGrid() {
var grid = document.getElementById('<%=GridView1.ClientID%>');
var div = document.getElementById('SIPDIV');
var name = "";
var namearray = new Array();
if (grid.rows.length > 0) {
for (i = 0; i <= grid.rows.length - 1; i++) {
var cell = grid.rows[i].cells[0];
for (j = 0; j < cell.childNodes.length; j++) {
if (grid.rows[i].cells[0].childNodes[j].type =='checkbox') {
var cellPivot = false;
cellPivot = grid.rows[i].cells[0].childNodes[j].checked;
if (cellPivot == true) {
//name += grid.rows[i].cells[1].innerHTML;
if (name == "") {
name = grid.rows[i].cells[1].childNodes[1].innerText;
}
else{
name += "," + grid.rows[i].cells[1].childNodes[1].innerText;
}
}
}
}
}
var IDQuery = SplitValues(name);
window.open(IDQuery,"Lync");
}
}
var emailid = "";
var sipId = "";
function SplitValues(emailid) {
var Emailarr = new Array();
Emailarr = emailid.split(",");
for (i = 0; i < Emailarr.length; i++)
{
if (i == 0)
{
sipId = "im:<sip:" + Emailarr[i] + ">";
}
else
{
sipId = sipId + "<sip:" + Emailarr[i] + ">";
}
}
return sipId;
}
</script>
aspx Html Code:
<asp:GridView ID="GridView1" runat="server" EnableModelValidation="True"
onrowdatabound="GridView1_RowDataBound">
<HeaderStyle BackColor="#099BC4" ForeColor="White" Wrap="True" />
<Columns>
<asp:TemplateField ShowHeader="true" HeaderText ="">
<HeaderTemplate>
<asp:CheckBox runat="server" ID="CheckBox2" Checked="false"/>
</HeaderTemplate>
<ItemTemplate >
<asp:CheckBox ID="CheckBox1" runat="server" Checked="false" >
</asp:CheckBox>
</ItemTemplate>
<ItemStyle Width="30px" BackColor="AliceBlue" />
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Button ID="Button1" runat="server" Text="Start Conference"
onClientClick="getGrid()"/>
C# Code:
SPFieldUserValueCollection fvc = new SPFieldUserValueCollection();
DataTable dt = new DataTable();
DataRow dr;
protected void Page_Load(object sender, EventArgs e)
{
try
{
dt.Columns.Add("Users");
SPWeb web;
web = SPContext.Current.Web;
SPGroupCollection collGroups = web.Groups;
SPList list = web.Lists["UserGroup"];
SPFieldUserValueCollection fvc = new SPFieldUserValueCollection();
foreach (SPListItem item in list.Items)
{
string fieldValue = item["UserName"].ToString();
Getusers(fieldValue);
}
}
catch (Exception ex)
{
Label1.Text = ex.Message;
Label1.Visible = true;
}
}
void Getusers(string fieldValue)
{
SPWeb web;
web = SPContext.Current.Web;
fvc = new SPFieldUserValueCollection(web, fieldValue);
foreach (SPFieldUserValue userValue in fvc)
{
SPUser user = userValue.User;
}
//string Html = string.Empty;
GetPresenceHTMLFromUVC(SPContext.Current.Site, fvc);
// Label1.Text += Html;
}
public void GetPresenceHTMLFromUVC(SPSite thisSite, SPFieldUserValueCollection uvc)
{
StringBuilder html = new StringBuilder("");
using (SPWeb thisWeb = thisSite.RootWeb)
{
foreach (SPFieldUserValue uv in uvc)
{
string sipAddress = "";
//Get the sip address if it exists
SPListItem user = thisWeb.SiteUserInfoList.GetItemById(uv.LookupId);
if (user["SipAddress"] != null)
{
sipAddress = user["SipAddress"].ToString();
}
//construct the html for this user and add to overall html
html.Append(String.Concat(
"<div id\"PresenceLink"
, sipAddress
, "\">"
, "<img border=\"0\" height=\"12\" src=\"/_layouts/images/imnhdr.gif\" onload=\"IMNRC('"
, sipAddress
, "')\" ShowOfflinePawn=\"1\" style=\"padding-right: 3px;\" id=\"PresencePawn"
, sipAddress
, "\" alt=\"presence pawn for "
, sipAddress
, "\"/>"
, "<a href=\""
, thisWeb.Url
, "/_layouts/userdisp.aspx?ID="
, uv.LookupId
, "\" id=\"ProfileLink"
, sipAddress
, "\">"
, uv.User.Name
, "</a></div><div id='SIPDIV' style='display:none'>"+sipAddress+"</div>"
//, "</a></div><div id='"+sipAddress+"' style='display:none'></div>"
));
dr = dt.NewRow();
dr["Users"] = html;
dt.Rows.Add(dr);
//Bind data into gridview
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
foreach (TableCell cell in e.Row.Cells)
{
if (e.Row.Cells.GetCellIndex (cell)!=0)
{
cell.Text = HttpContext.Current.Server.HtmlDecode(cell.Text);
}
}
}
OutPut:
No comments:
Post a Comment