Posts

C#: How do I sort a generic list?

There are two simple methods available: OrderBy/OrderByDescending and Sort. The one you choose depends on your intended outcome. If you want 'in place' sorting (ie: within the existing object), then use myItems.Sort((x,y) => string.Compare(x.MyProperty, y.MyProperty)); If you want to assign the outcome to a new variable, the use var mySortedResults = myItems.OrderBy(x=> x.MyProperty).ToList()

SQL Server: Add a 'not null' column to an existing table

I tried to add a 'not null' column to an existing table, but SQL Server (rightfully) complained. I had two options - give the column a default value (no thanks) or add a nullable column and change it. I chose the latter. 1. Add a nullable column Alter table [Foo] add [MyFoo] int null 2. Set all the values to a value Update [Foo] set [MyFoo] = 1 3. Set the column to be 'not null' Alter table [Foo] Alter Column [MyFoo] int not null

Javascript: Get the current root url

This may not be the easiest way, but is certainly worked for me. var url = $(location).attr('href').replace(window.location.pathname, '').replace(window.location.search, '');

SharePoint: How do I add and remove unique permissions in Powershell?

Here are two useful scripts to help you on your way: function SetPermission($url, $list, $group, $permission) { $spWeb = Get-SPWeb $url $selectedList = $spWeb.Lists[$list] # Assign the "Contribute" RoleDefition to the site's visitors group $visitorsSPGroup = $spWeb.Groups[$group] If (! $selectedList.HasUniqueRoleAssignments) { $selectedList.BreakRoleInheritance($true) } $assignment = New-Object Microsoft.SharePoint.SPRoleAssignment($visitorsSPGroup) $assignment.RoleDefinitionBindings.Add(($spWeb.RoleDefinitions | Where-Object { $_.Type -eq $permission })) $selectedList.RoleAssignments.Add($assignment) $selectedList.Update() $spWeb.Dispose() } function RemovePermission($url, $list, $group) { $spWeb = Get-SPWeb $url $selectedList = $spWeb.Lists[$list] $visitorsSPGroup = $spWeb.Groups[$group] If (!$selectedList.HasUniqueRoleAssignments) { $selectedList.BreakRoleInheritance($true) } $web.AllowUnsafeUpdates = $true; ...

PowerShell: Loop through all the sites in a site collection (not recursive)

$site = Get-SPSite "http://mysitetosearch.com" $topWeb = Get-SPWeb $site.Url $site | Get-SPWeb -limit all | ForEach-Object { Write-Host "Found $_.Name"; }

SharePoint 2013: HTTP 500 error when sending an email from a SharePoint Designer workflow

I recently encountered this problem for a client and the cause had me stumped. I did all the basic checking 1. Check the UPS was up to date 2. Made sure that the Workflow Manager was correctly installed 3. Made sure that the firewall was not blocking the WF manager port (12290 or 12291). Still nothing. The problem (it seems) comes from Document Library 'Advance Settings'; the document library had 'require checkout' set. I did not think anything of it, but once I removed it the workflow executed as expected. Its a strange behaviour but at least its something to look at when trying to resolve the issue.

SharePoint 2013: Can I add a document to a generic list?

Image
The short answer is yes. In the advanced settings for a list, there is an 'enable attachments' setting.