Skip to content

Instantly share code, notes, and snippets.

@OlafD
OlafD / MergePdf.cs
Created March 6, 2019 11:10
Merge to pdf files from their stream objects into a MemoryStream using Aspose.Pdf.
static MemoryStream MergePdfDocuments(Stream pdf1, Stream pdf2)
{
MemoryStream result = null;
Aspose.Pdf.Document pdf1Document = new Aspose.Pdf.Document(pdf1);
Aspose.Pdf.Document pdf2Document = new Aspose.Pdf.Document(pdf2);
Aspose.Pdf.Document pdfResult = new Aspose.Pdf.Document();
pdfResult.Pages.Add(pdf1Document.Pages);
@OlafD
OlafD / ConvertDocX2PdfWithAspose.cs
Created March 6, 2019 10:48
Simple sample code to convert a docx-file to pdf using Aspose.Words. The relevant part is the method SaveAsPdf(). The Nuget package for Aspose.Words needs to be added to the project.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using Aspose.Words;
using Aspose.Pdf;
@OlafD
OlafD / GetSPOVersionHistory.cs
Created January 24, 2019 14:09
A program.cs for a simple console application that shows the version history for a listitem form a SharePoint Online list. This code comes from a simple test application and needs some rework to get a better performance.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security;
using Microsoft.SharePoint.Client;
namespace VersioningTester
{
@OlafD
OlafD / GetFieldPositionInView.ps1
Created January 18, 2019 07:24
For a list given by its name and for a view in this list given by its name, get the zero-based position of the field given by its internal name. When the field does not exist in the view, the result is -1.
param (
[string]$Listname,
[string]$Viewname,
[string]$Fieldname
)
$result = -1
$currentPosition = -1
$view = Get-PnPView -List $Listname -Identity $Viewname -Includes ViewFields
@OlafD
OlafD / GetFieldPositionInContentType.ps1
Created January 18, 2019 07:21
Get the zero-based position of a field, given by its internal name in a content type given by its name. When the field does not exist in the content type, the return value is -1.
param (
[string]$ContentTypeName,
[string]$FieldName
)
$result = -1
$currentPosition = -1
$ct = Get-PnPContentType -Identity $ContentTypeName
@OlafD
OlafD / ReorderContentTypeFields.ps1
Created January 18, 2019 07:18
Change the field order in a content type by PowerShell. As parameters, we need the name of the content type and the internal name of the field to reorder, and when the Mode parameter is set to Position the zero based number of the new position of the field. The script uses Load-CSOMProperties, a function implemented in the PBSPOPS module. When t…
param (
[Parameter(Mandatory=$true)]
[string]$ContentType,
[Parameter(Mandatory=$true)]
[string]$FieldName,
[ValidateSet("First", "Last", "Position")]
[string]$Mode,
[string]$NewPosition
)
@OlafD
OlafD / Add-jQuery.ps1
Created January 10, 2019 08:54
With the PowerShell PnP extensions make jQuery available in the complete site collection in SharePoint Online.
$jsLink = Add-PnPJavaScriptLink -Name "jQuery" -Url "https://code.jquery.com/jquery.min.js" -Sequence 10 -Scope Site
@OlafD
OlafD / AddChoiceToChoiceField.ps1
Created January 8, 2019 13:57
In SharePoint Online, add a new choice value to an existing choice field. The fieldname in the example is "MyChoiceField" with 3 very simple choices. A fourth choice is added by the script. A connection to the SharePoint site must be established.
$field = Get-PnPField -Identity "MyChoiceField"
$ctx = Get-PnPContext
$fieldChoice = [Microsoft.SharePoint.Client.ClientContext].GetMethod("CastTo").MakeGenericMethod([Microsoft.SharePoint.Client.FieldChoice]).Invoke($ctx, $field)
$ctx.Load($fieldChoice)
Invoke-PnPQuery
@OlafD
OlafD / RestAgainstSharePointOnline.ps1
Last active January 21, 2019 14:22
From the PowerShell PnP extensions installed on any machine, copy the files Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.Runtime.dll to the same folder, as this script. Then, you can execute a Rest call like .\RestAgainstSharePointOnline.ps1 -Url https://{yourtenant}.sharepoint.com/_api/web -UserName {youruser} -Password {your…
param (
[string]$Url,
[string]$UserName,
[string]$Password,
[Microsoft.PowerShell.Commands.WebRequestMethod]$Method = [Microsoft.PowerShell.Commands.WebRequestMethod]::Get
)
$currentPath = (Get-Item -Path ".\").FullName
Add-Type -Path "$currentPath\Microsoft.SharePoint.Client.dll"
@OlafD
OlafD / ShowImageInPopupDialog.txt
Last active November 28, 2018 16:17
Snippet for a SharePoint Script Editor webpart, to show an image and on a click show the image
<script type="text/javascript">
var dlgOptions;
function setDlgOptions(pictureUrl) {
var htmlFragment = document.createElement("img");
htmlFragment.setAttribute("src", pictureUrl);
htmlFragment.setAttribute("width", "800");
htmlFragment.setAttribute("height", "600");