I’m posting this as a useful reminder. It outlines how alerts can now be created via CSOM.
New SharePoint CSOM version released for SharePoint Online – February 2017
The included code sample is in C#, but I’ve translated it to PowerShell – which suits my administrative needs better.
[System.Reflection.Assembly]::LoadWithPartialName( "Microsoft.SharePoint.Client" ) | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName( "Microsoft.SharePoint.Client.Runtime" ) | Out-Null
# Set variables
$path = "C:\Temp\Usernames.txt"
$url = "https://xxxxxx.sharepoint.com/sites/help"
$list = "My List"
$title = "$list (Auto-subscribed)"
# Prompt the administrator to log in
$credential = Get-Credential -Credential $null
# Create a connection to SharePoint Online
$context = New-Object Microsoft.SharePoint.Client.ClientContext( $url )
$context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials( $credential.UserName, $credential.Password )
# Retrieve the targeted web
$web = $context.Web
$context.Load( $web )
# Loop through the provided usernames and create a new alert for each one
$usernames = Get-Content -Path $path
foreach ( $username in $usernames )
$user = $context.Web.EnsureUser( $username )
$alert = New-Object Microsoft.SharePoint.Client.AlertCreationInformation
$alert.List = $context.Web.Lists.GetByTitle( $list )
$alert.AlertFrequency = [Microsoft.SharePoint.Client.AlertFrequency]::Daily
$alert.AlertTime = ( Get-Date ).AddDays( 1 )
$alert.AlertType = [Microsoft.SharePoint.Client.AlertType]::List
$alert.AlwaysNotify = $false
$alert.DeliveryChannels = [Microsoft.SharePoint.Client.AlertDeliveryChannel]::Email
$alert.Status = [Microsoft.SharePoint.Client.AlertStatus]::On
$alert.Title = $title
$alert.User = $user
$alert.EventType = [Microsoft.SharePoint.Client.AlertEventType]::All
$alert.Filter = "1"
$guid = $user.Alerts.Add( $alert )
Another note to myself…
When wanting to programmatically hide a WebPart, don’t try to set it’s Visible property to False. This will cause you lots of trouble and create errrors. The correct method is to set its Hidden property to True.
if (items.Count == 0)
this.Hidden = true;
An interesting forumla to remember for rounding numbers to the nearest X.
Int32 value = 43.7;
Int32 toNearest = 5;
Int32 result = Math.Round(value / toNearest) * toNearest;
These design solutions were created as part of the University’s move from a 10 year old, bespoke, Classic ASP driven Intranet (which I originally developed) to Microsoft SharePoint 2010. Their purpose was to act as a starting point for discussion among staff and students and to generate feedback.
There seems to be no built-in function or property to quickly return the correct URL for a SharePoint list item. The obvious property, SPListItem.URL, always returns an invalid URL along the lines of
http://sharepoint/Lists/MyList/155_.000. Not ideal.
To get around this and return a correctly formatted web address, you can use the following code:
item.Web.Url + "/" + item.ParentList.Forms[PAGETYPE.PAGE_DISPLAYFORM].Url + "?ID=" + item.ID
ArticleCollection articles = new ArticleCollection();
if (articles.Count > 0)
foreach (Article a in articles)
Response.Write(a.Headline + ", ");
BigInt = Int64 (Long)
Int = Int32 (Integer)
SmallInt = Int16 (Short)
TinyInt = Byte
e.g. byte recurrenceType = reader.GetByte(8);
Clipboard.SetText( “Hello World!”);
Short and sweet! 🙂
Thanks to a reply to one of my posts within the
SubSonic forums, I was pointed to this very nifty utility at Developer Fusion – a tool that will automatically convert C# code to VB.Net and back again.
Posting this for future reference…