Saturday, November 26, 2011

Check Current User Gorup In SharePoint Object Model


To manage permission we create Groups in SharePoint. In Custom SharePoint application or webpart, we have to check user permissions or may have activate different  functionality.

For that We need to check Current User Group..

Here is a function that will return true/false by providing Group Name!

private bool IsCurrentUserMemberOfGroup(string GroupName)
        {
            try
            {
              return SPContext.Current.Web.IsCurrentUserMemberOfGroup(SPContext.Current.Web.Groups[GroupName].ID);               
            }
            catch (Exception)
            {
                return false;
            }
        }


You may provide web object for performance tuning.

Friday, November 4, 2011

Remove Lookup Hyperlink from SharePoint List view using JQuery

When you use lookup to the list automatically SharePoint give link to the lookup item on list view.
Check it out….
Lookup column with Hyperlinks
But many times, we don’t want  those Hyperlinks on the list view, as we can remove it from SharePoint Designer but it’s a hectic task.
Simply add JQuery  to remove those Hyperlinks.
First, get the URL of the link using Developer tool of IE or Firebug of Firefox browser. we are going to some part of URL in the below code.

Get URL using Developer tool of IE


Then copy following JQuery code to the HTML form WebPart on list view.

Jquery For MOSS 2007/WSS 3.0:


    
    

Note: Change highlighted text as per your context.
Jquery For SharePoint 2010/SharePoint Foundation 2010:





Note: Change highlighted text as per your context.

If View is Grouped, set list view setting "By default, show groupings:" to  Expanded


List View setting: Make sure that By default, show groupings: Expanded

List view with removed hyperlinks to Lookup columns:

Live simple!

How to rename the list view column name using JavaScript

We can change column name from JavaScript, it will not affect your existing functionality or custom code and also no need to change column name from SharePoint Designer as it is a troublesome task.
Follow this steps….
1. Get column Id using Developer tool of IE or Firbug of Firefox.
Get Column ID using Developer tool of IE

2. Add following JavaScript in HTML form web part on the list view.
<script type="text/javascript">
//This script is developed by Amit Phule # http://amitphule.blogspot.com/
 _spBodyOnLoadFunctionNames.push("ChangeColumnName"); // Call ChangeColumnName function on PageLoad
        function ChangeColumnName() {
            RenameColumn('diidSortAuthor', 'Author'); //Provide Column ID and New Column name
        }
        function RenameColumn(colID, NewHeader) {
            try {
                document.getElementById(colID).innerHTML = NewHeader; //Change Header Name
                document.getElementById(colID).title = "Sort by " + NewHeader; // Change Tooltip value
            }
            catch (err) {
                alert('Invalid Column ID:' + colID);
            }
        }
 </script>

Old column Name:
New Column Name:


Live simple !