Tuesday, January 29, 2013

Microsoft Lync configuration with SharePoint server

Microsoft Lync configuration with SharePoint server & Site

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:


Friday, January 11, 2013

Getting Hierarchy Of User Profiles In SharePoint Using C#



Getting Hierarchy Of User Profiles In SharePoint Using C#


Below is the examples respectively for 
  • Find immediate manager of a particular user.
  • All the users who reports the same manager. 
  • All the managers above in the chain for a particular user
Note : 

Add Following Dll Before Coding.

"Microsoft.Office.Server.dll & Microsoft.Office.Server.UserProfiles.dll"

Location For The Dll:
  • C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI\Microsoft.Office.Server.dll
  • C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI\Microsoft.Office.Server.UserProfiles.dll

Find Manager for currently logged in user.
private void GetManegerProfile()
 {
 SPSite site;
 SPWeb web;
 SPServiceContext serviceContext;
 UserProfileManager profiles;
 UserProfile profile; 
 try
  {
    using (site = new SPSite(SPContext.Current.Web.Url))
    {
      using (web = site.OpenWeb())
      {
        serviceContext = SPServiceContext.GetContext(site);
        profiles = new UserProfileManager(serviceContext);
        //Getting the profile of logged in user.
       profile = profiles.GetUserProfile(web.CurrentUser.LoginName);
      //Getting profile of the manager of the logged in user.
      profile = profile.GetManager();
      }
    } 
  }
catch { }
}
Find all the user who reports the same manager as logged in user. 
private void GetManegerProfile()
{
SPSite site;
SPWeb web;
SPServiceContext serviceContext;
UserProfileManager profiles;
UserProfile profile;
List<UserProfile> peers; 
try
{
  using (site = new SPSite(SPContext.Current.Web.Url))
  {
   using (web = site.OpenWeb())
    {
      serviceContext = SPServiceContext.GetContext(site);
      profiles = new UserProfileManager(serviceContext);
      //Getting the profile of logged in user.
      profile = profiles.GetUserProfile(web.CurrentUser.LoginName);
      //Getting peers of the logged in user.
      peers = new List<UserProfile>(profile .GetPeers());
      }
    }
  }
catch { }
}

Find all the managers above in the chain for the logged in user.

private void GetManegerProfile()
{
SPSite site;
SPWeb web;
SPServiceContext serviceContext;
UserProfileManager profiles;
UserProfile profile;
List<UserProfile> managers;
try
{
using (site = new SPSite(SPContext.Current.Web.Url))
{
using (web = site.OpenWeb())
  {
   serviceContext = SPServiceContext.GetContext(site);
   profiles = new UserProfileManager(serviceContext);
   //Getting the profile of logged in user.
   profile = profiles.GetUserProfile(web.CurrentUser.LoginName);
   //Getting manager profiles of the logged in user.
    managers =new List<UserProfile>( profile.GetManagers());
    }
  }
}
catch { }
} 

Thursday, January 10, 2013

WebPart Custom Properties For "Site Url","List Url","Item Url" Etc

Web Part Custom Properties For "Site URL","List URL","Item URL" Etc


WebPart.CS file

protected override void CreateChildControls()
        {
            CAFUserControl control = Page.LoadControl(_ascxPath) as CAFUserControl;

            if (control != null)
            {
                control.WebPart = this;
            }

            Controls.Add(control);
       }

        [WebBrowsable(true), Category("CAF Properties"), Personalizable(PersonalizationScope.Shared), WebDisplayName("Enter OEM list name")]
        public String OEMListName { get; set; }

        [WebBrowsable(true), Category("CAF Properties"), Personalizable(PersonalizationScope.Shared), WebDisplayName("Enter Licensing list name")]
        public String LicensingListName { get; set; }

        [WebBrowsable(true), Category("CAF Properties"), Personalizable(PersonalizationScope.Shared), WebDisplayName("Enter Purchasing list name")]
        public String PurchasingListName { get; set; } 


UserControl.aspx.cs file

public partial class CAFUserControl : UserControl
    {
public CAF WebPart { get; set; }
}

Eg: ascx Path ( @"~/_CONTROLTEMPLATES/...." )
  private const string _ascxPath = @"~/_CONTROLTEMPLATES/AmexCalendar_VWP/AmexCalendar_VisualWebPart/AmexCalendar_VisualWebPartUserControl.ascx";

Monday, December 31, 2012

JavaScript for differentiation of two different dates & Exclude the Saturdays and sunsays in total days

JavaScript for getting Total days between of two dates & Exclude the Saturdays and Sundays in total days.

 Code: 


function DateDifference() {
            var startDate = document.getElementById('<%= txtStartDate.ClientID%>').value;
            var endDate = document.getElementById('<%= txtEndDate.ClientID%>').value;
            var startDateSplit = startDate.split("/");
            var endDateSplit = endDate.split("/");
           //getting Start Date,End Date
            var stDate = new Date(startDateSplit[2], startDateSplit[0] - 1, startDateSplit[1]);
            var enDate = new Date(endDateSplit[2], endDateSplit[0] - 1, endDateSplit[1]);
            //getting difference B/W Start Date & End Date
            var difference = (enDate.getTime() - stDate.getTime()) / (1000 * 60 * 60 * 24);
            var LeaveCount = difference + 1;

            if (stDate.getDay() == 0) {
                LeaveCount = LeaveCount - 1;               
            }
            else if (stDate.getDay() == 6) {
                LeaveCount = LeaveCount - 1;
            }

            var loopDate = new Date();
            loopDate = stDate;
            // Excluding Sat ,Sun in Selcted Dates
            for (var i = 1; i < difference + 1; i++) {
                var NextDate = new Date(loopDate.getYear(), loopDate.getMonth(), loopDate.getDate() + 1);               
                var Ndate = NextDate.getMonth() + 1 + "/" + NextDate.getDate() + "/" + NextDate.getYear();
                var NdateSplit = Ndate.split("/");
                var NxtDate = new Date(NdateSplit[2], NdateSplit[0] - 1, NdateSplit[1]);
                loopDate = NxtDate;
              
                if (NxtDate.getDay() == 0) {
                    LeaveCount = LeaveCount - 1;                  
                }
                else if (NxtDate.getDay() == 6) {
                    LeaveCount = LeaveCount - 1;                  
                }
            }           
            document.getElementById('<%= txtTotalDays.ClientID%>').value = LeaveCount;
        }

Monday, December 17, 2012

How to Enable Document Information Panel in SharePoint 2010


How to Enable Document Information Panel in SharePoint 2010
The SharePoint 2010 Document Information Panel allows users to enter metadata for Microsoft-based documents that are stored in SharePoint. However, the SharePoint 2010 Document Information Panel is not visible by default.  To view the SharePoint 2010 Document Information Panel, click the "Show Document Panel" option under the Info menu.

During an implementation of Sharepoint 2010 for an Australian client, the client had a requirement for showing the Document Information Panel whenever a document is opened from a particular document library. IOTAP was able to meet this requirement by enabling the Document Information Panel in the Document Library settings.
How to Enable SharePoint 2010 Document Information Panel for a Document Library:
1.       Navigate to the Document Library for which the Document Information Panel needs to be enabled
2.       Click on Library Settings in the Library Tools Ribbon
3.       In the Library Settings page, click Document Content Type which is located under the Content Type Category
4.       Click on Documents Information Panel Settings under Settings

Documents Information Panel Settings

5.       Select the check box for “Always show Document Information Panel on document open and initial save for this conten type”
6.       Click OK

Now, whenever a document is opened from the document library the Document Information Panel will be displayed as shown below.
Document Information Panel in SharePoint 2010

Wednesday, December 5, 2012

50 Limitations of SharePoint Sandboxed Solutions



1. Deployment at site collection level (No Web Application-scoped Features or Farm-scoped Features). So, If you have 100 site collections, then you have to deploy the same sandbox solution to 100 site collections. 

2. No SPSecurity - Therefore no Elevated Privileges

3. You can't use SPSite object to get other site collections. (But you can use it to get current site as : SPSite site = SPContext.Current.Site)

4. Visual webparts are not supported (But you can use the "Visual Studio 200 SharePoint Power Tools" to get this functionality)

5. cannot call to the network resources. E.g. You cannot read/write to a database on the server (But you can use Silverlight)

6. Only "No code" workflows allowed. No Visual studio workflows (But the workflows without classes which are imported and edited in Visual studio will work!)

7. No support for System.IO, Therefore you Cannot read/write to the file system. 

8. HideCustomAction, CustomActionGroup are not allowed. But you can use <CustomAction>

9. Remember, Resource Usage Quotas/Limits applied on Sandboxed solutions http://msdn.microsoft.com/en-us/library/gg615462.aspx

10. No Feature stapling supported.

11. Can't write to registry (But you can read)

12. Limited Server Object Model MSDN: http://msdn.microsoft.com/en-us/library/gg615454.aspx

13. Can't set cookies in the sandbox. Use JQuery plugin instead http://plugins.jquery.com/project/cookie

14. No call to external WCF/web services such as HTTP calls (But we can use AJAX)

15. Content Type Binding is not supported

16. No support for custom Timer jobs

17. Can't use SharePoint mapped folders such as _layouts

18. Can't export a Sandboxed Web Part

19. Microsoft.SharePoint.WebControls and Microsoft.SharePoint.WebPartPages Namespace are not available.

20. Managed Metadata - No programmatic access to taxonomy object model. 

21. No ADO.NET support!

22. No support for SPUtility.SendEmail, So you can't Send Mails using this class.

23. No caching support

24. No Custom HTTP Modules

25. No developer dashboard

26. No Site Definition

27. Can't use controls for delegation

28. No Business Connectivity Services support

29. No Localization support

30. No SPWebConfigModification usage

31. Most of the Microsoft.SharePoint.Administration are disabled

32. No Document converters

33. No User Control support.

34. NO Custom service applications 

35. SharePoint web controls (such as SPTreeView) are not supported

36. ClientScriptManager is not available - No access to ScriptManager.

37. Can't access the event viewer for logging 

38. No PropertyBags of SharePoint Object model are not accessible,( But you can use SPWeb.AllProperties or custom list to store settings)

39. No GAC Deployment - Your solutions will be stored in content database. Can't deploy assemblies to GAC and Cannot call assemblies deployed out of Global Assembly Cache 

40. CustomPropertyToolPart not supported

41. Can't create application pages or site pages with code behind

42. No Server side redirects, such as Response.Redirect, Server.Transfer,  SPUtility.Redirect.

43. Can't access some of the enterprise services like UserProfile, Search 

44. Can't access dlls from BIN and resources files(.resx) 

45. Can't access code that is not marked to allow partially trusted callers

46. Can't access Cache object.

47. HttpRequest.Files collection will not contain anything

48. Only SPLimitedWebPartManager is available.

49. SharePoint Web controls (namespace SharePoint.WebControls) are not available,

50. Last but not least: site Template Binding is not supported.

Monday, November 26, 2012

Filter SharePoint List by Workflow Status


Filter SharePoint List by Workflow Status

Often we need to filter a SharePoint list by  the status of a workflow.

This is rather simple and can be done in the same way as filtering any other field.

The only thing you need to know is that the status of the workflow is an integer, not a text.  So we can’t add a filter like ‘Workflow name’ IS EQUAL TO ‘In Progress’

The following list gives the integer values of each status.
This data can also be used within InfoPath to change the layout of the form depending on the status of the workflow.

A blog was written earlier how to do this:
List of Workflow statuses

  •      0 - Starting
  • 1 - Failed on Start
  • 2 - In Progress
  • 3 - Error Occurred
  • 4 - Canceled
  • 5 - Completed
  • 6 - Failed on Start (retrying)
  • 7 - Error Occurred (retrying
  • 15 - Canceled
  • 16 - Approved
  • 17 - Rejected