Thursday, June 14, 2012

Get All Users from a User Collection



SPFieldUserValueCollection afterAttendees=new SPFieldUserValueCollection(web, properties.AfterProperties["Attendees"].ToString());

to get a single user use foreach with SPFieldUserValue

Check if Current User have Specific Permissions


SPRoleDefinition roleDefinitionRead = spWeb.RoleDefinitions.GetByType(SPRoleType.Reader);
spList.DoesUserHavePermissions(user, roleDefinitionRead.BasePermissions);

Wednesday, June 13, 2012

Some useful power shell commands


Copy DLL's From GAC

C:\Windows\assembly\GAC_MSIL\cd dllname
C:\Windows\assembly\GAC_MSIL\dllname\cd dllvirsion_dllpublickytoken(simply press tab after typing cd to get version and public key token)
C:\Windows\assembly\GAC_MSIL\dllname\dllvirsion_dllpublickytoken\copy dllname path_to_save


Set UIVersion for a site

$web = Get-SPWeb http://suinshr00002:666
  $web.UIVersion=3
  $web.Update()

set UI Version  for all sites of a site collection

$w = get-spweb http://sharepoint/sites/team/subsite
$w.webs | ForEach-Object {$_.UIversion = 4; $_.UIVersionConfigurationEnabled = $false; $_.update()} 

Tuesday, June 12, 2012

Disable Event Handlers when Updating a list Programatically

HandleEventFiring eventFiring = new HandleEventFiring();
eventFiring.AccDisableEventFiring();
listItem.Update();
eventFiring.AccEnableEventFiring();


-------------------

public class HandleEventFiring : SPItemEventReceiver
        {
            public void AccDisableEventFiring()
            {
                this.DisableEventFiring();
            }

            public void AccEnableEventFiring()
            {
                this.EnableEventFiring();
            }
        }

Friday, June 8, 2012

Calculate Business days - SharePoint List calculated column


The following calculated column formula calculates business excluding weekends, based on start date and end date columns in a list.

=IF(AND((WEEKDAY(To,2))<(WEEKDAY(From,2)),((WEEKDAY(From,2))-(WEEKDAY(To,2)))>1),(((DATEDIF(From,To,"D")+1))-(FLOOR((DATEDIF(From,To,"D")+1)/7,1)*2)-2),(((DATEDIF(From,To,"D")+1))-(FLOOR((DATEDIF(From,To,"D")+1)/7,1)*2)))

From is the start date column name here and To is the end date.