Wednesday, May 15, 2013

jQuery SPServices to get current user sharepoint groups

In this post we are going to get information of all the sharepoint user groups in which current user belongs using SPServices.

Below is the jQuery code snippet which will do this action.
In this example we will be looping all the groups which the current user is present and adding it to the variable  loggedinUserGroup.

// add the ref of jQuery file
<script type="text/javascript" src="/style library/jquery-1.7.2.js"></script>
// add the ref of jQuery SPServices file
<script type="text/javascript" src="/style library/jquery.SPServices-0.7.0.min.js"></script>
<script type="text/javascript">
var loggedinUserGroup;
$(document).ready(function() {
 Getrolesforuser();
 alert(loggedinUserGroup);
});
function Getrolesforuser()
{
 loggedinUserGroup="";
 $().SPServices({ 
  operation: "GetGroupCollectionFromUser", 
        userLoginName: $().SPServices.SPGetCurrentUser(), 
        async: false, 
        completefunc: function(xData, Status)
        {
         $(xData.responseXML).find("Group").each(function()
         {
              if(loggedinUserGroup=="")
              {
                  loggedinUserGroup = $(this).attr("Name");
              }
              else
              {
                  loggedinUserGroup = loggedinUserGroup + "\n"+ $(this).attr("Name");
              }
         });
               
  }
 });
}

</script>

Hope this helps... Follow this page for more updates.
Related post- jQuery spservices to get current user name for sharepoint site
Related post- How to display user information using ProfilePropertyLoader in sharepoint

Monday, March 18, 2013

Implementing Google chrome frame Plugin to your website


Google Chrome frame lets web developers create web features based on technologies that are not yet available in some versions of Internet Explorer, such as rich text editing and faster Javascript execution. If you use Internet Explorer, you can still use it to view websites that contain such features, by first downloading the Google Chrome Frame plugin.
This google chrome frame plugin is also used to avoid the memory leakage in IE if our site is using AJAX,jQuery. If once we have installed this plugin we just need to change the meta tag so that IE browser will render using chrome engine. Ref this link for more details.
In this Post we are going to Implement Google chrome frame Plugin to our website wherein we will be showing a div(ref figure below) on top of our page, only in Internet Explorer and if Google chrome frame Plugin is not installed.

Below are the steps:
Step1: Create a above div and place it at the top of the page. Make the div style as display:none

Step2: Checking google chrome frame plugin is installed on the machine or not.

Below is the function that can do the trick
function IsGoogleChromePluginInstalled() {
    try {
        var i = new ActiveXObject('ChromeTab.ChromeFrame');
        if (i) {
            return true;
        }
    }
    catch (e) {
    }
    return false;
}

Call the above function in the document.ready function. If the function above function returns false(means GCF plugin not installed) then make the above created div style as display:block. So that it will display the above div to the user.

Step3: Call the below function on the onclick= installGoogleChromeFrame(); for Install Now button

function installGoogleChromeFrame() {   
    if ($(".chromeFrameOverlayContent").length > 0) {
        $(".chromeFrameOverlayContent, .chromeFrameOverlayUnderlay").show();
    }
    else {
        CFInstall.check({
            url: document.location.protocol + "//" + {SingleUser Or Multi User url},
            mode: "overlay",
            destination: window.location
        });

        $(".chromeFrameOverlayContent, .chromeFrameOverlayUnderlay").show();
        var chromeframeheight = document.body.scrollHeight;
        $('.chromeFrameOverlayUnderlay').css('height', chromeframeheight);
        $("#chromeFrameCloseButton").click(function () {
            $(".chromeFrameOverlayContent, .chromeFrameOverlayUnderlay").css({ display: "none" });
        });

    }
}

Single user installation:

Multiple user installation:

Step4:
With the above three steps we are good to show a message to install the Google chrome frame Plugin.
When user clicks on Install Now button an overlay will comes up on top of our webpage asking user to install.

Hope this helps…


Saturday, February 23, 2013

TreeView with the nodes as document library names using Sharepoint2010


In this post we are going to construct a TreeView with the nodes as sharepoint document library names using Sharepoint2010
Root Node will be the Site Url. 

Before we proceed with the code add a treeview with ID as myTreeView to your page. 
Below is the code snippet.

try
            {
                using (SPSite site = new SPSite("<<http://site Url>>"))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        SPListCollection docLibraryColl = web.GetListsOfType(SPBaseType.DocumentLibrary);

                        List<string> docLibrariesList = new List<string>();
                        foreach (SPList list in docLibraryColl)
                        {
                            if (!list.Hidden)
//if you don’t want style library and Forms templates then use below condition instead of above
                            //if (!list.Hidden && list.title != "Style Library" && list.title != "Form Templates")
                            {
                                SPDocumentLibrary doclib = (SPDocumentLibrary)list;
                                string docLibTitle = doclib.Title;
                                int docsCount = doclib.ItemCount;
                                docLibrariesList.Add(docLibTitle);
                            }
                        }

                        TreeNode RootNode = new TreeNode();
                        //Here we are binding the root node as Site Url
   RootNode.Text = "<<http://site url>>";

                        foreach (string docLibrary in docLibrariesList)
                        {
                            TreeNode childNode = new TreeNode();
                            childNode.Text = docLibrary;
                            RootNode.ChildNodes.Add(childNode);
                        }
   // myTreeView is treeview controls ID present on the aspx page
                        myTreeView.Nodes.Add(RootNode);

                    }
                }
            }
            catch (Exception ex)
            {

            }


Hope this helps..

Popular Posts