Skip to content

Instantly share code, notes, and snippets.

View cjvandyk's full-sized avatar

Cornelius J. van Dyk cjvandyk

View GitHub Profile
@cjvandyk
cjvandyk / TSQL-Select-no-duplicates.sql
Created March 14, 2017 16:48
TSQL-Select-with-no-duplicates.
SELECT *
FROM tblSites
GROUP BY Url
HAVING count(Url) = 1;
@cjvandyk
cjvandyk / Powershell-Remove-duplicates-from-array.ps1
Created March 14, 2017 17:00
Powershell-Remove-duplicates-from-array-desc
$array = @("a", "b", "c", "b", "d", "a"); #Setup the array.
$array = $array | sort -unique; #Sort the array while using only unique values.
@cjvandyk
cjvandyk / Powershell-Remove-item-from-array.ps1
Created March 14, 2017 17:16
Powershell-Remove-item-from-array-desc
$list = @(); #Initialize the array.
$list += "Apple"; #$list = "Apple"
$list += "Orange"; #$list = "Apple", "Orange"
$list += "Tomato"; #$list = "Apple", "Orange", "Tomato"
$list += "Grape"; #$list = "Apple", "Orange", "Tomato", "Grape"
$list -= "Tomato"; # ERROR!!! You can't do this!
#but this works
$list = $list -ne "Tomato"; #$list = "Apple", "Orange", "Grape"
@cjvandyk
cjvandyk / Update-SPSiteUrl.ps1
Created April 27, 2017 13:20
This script updates the given site URL to the given new site URL.
[CmdletBinding()]
Param ([Parameter(Mandatory=$true, HelpMessage="Current site URL?")][ValidateNotNullOrEmpty()][string]$oldUrl,
[Parameter(Mandatory=$true, HelpMessage="Desired new site URL?")][ValidateNotNullOrEmpty()][string]$newUrl)
$validate = Get-SPSite $newUrl;
if ($validate -eq $null)
{
try
{
$site = Get-SPSite $oldUrl;
$site.Rename($newUrl);
@cjvandyk
cjvandyk / InfoPath-Attachment-Encoder.cs
Last active January 4, 2024 06:50
InfoPath Attachment Encoder Code
using System;
using System.IO;
using System.Text;
using System.Security.Cryptography;
using InfoPathAttachmentEncoding;
namespace InfoPathAttachmentEncoding
{
/// <summary>
/// InfoPathAttachment encodes file data into the format expected by InfoPath for use in file attachment nodes.
@cjvandyk
cjvandyk / InfoPath-Attachment-Decoder.cs
Created December 12, 2018 20:50
InfoPath File Attachment Decoder
using System;
using System.IO;
using System.Text;
namespace InfoPathAttachmentEncoding
{
/// <summary>
/// Decodes a file attachment and saves it to a specified path.
/// </summary>
public class InfoPathAttachmentDecoder
@cjvandyk
cjvandyk / Save-Decoded-Attachment.cs
Created December 12, 2018 21:01
Save decoded attachment
//Create an XmlNamespaceManager
XmlNamespaceManager ns = this.NamespaceManager;
//Create an XPathNavigator object for the Main data source
XPathNavigator xnMain = this.MainDataSource.CreateNavigator();
//Create an XPathNavigator object for the attachment node
XPathNavigator xnAttNode = xnMain.SelectSingleNode("/my:myFields/my:theAttachmentField", ns);
//Obtain the text of the node.
@cjvandyk
cjvandyk / getInfoPathAttachments.cs
Created December 13, 2018 14:18
Consuming an InfoPath document and a specified node path, decode all file attachments from the document and return them in a list of memory streams.
public List<System.IO.MemoryStream> getInfoPathAttachments(System.Xml.XmlDocument InfoPathDocument, string nodePath)
{
/// <summary>
/// Grab multiple attachments from an InfoPath form and
/// return them in a list of memory streams.
/// </summary>
List<System.IO.MemoryStream> files = new List<MemoryStream>();
System.Xml.XmlNamespaceManager nm = new System.Xml.XmlNamespaceManager(InfoPathDocument.NameTable);
nm.AddNamespace("my", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2014-07-12T15:29:09");
@cjvandyk
cjvandyk / RetrieveLoaderExceptions.cs
Created April 9, 2020 15:12
Retrieve LoaderExceptions
catch (Exception ex)
{
if (ex is System.Reflection.ReflectionTypeLoadException)
{
var typeEx = ex as ReflectionTypeLoadException;
var loadEx = typeEx.LoaderExceptions;
//Do something with loadEx
}
}
@cjvandyk
cjvandyk / AddNetStandardReference.xml
Created April 9, 2020 18:53
NetStandard reference
<configuration>
<system.web>
<compilation>
<assemblies>
<add assembly="netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51"/>
</assemblies>
</compilation>
</system.web>
</configuration>