Skip to content

Instantly share code, notes, and snippets.

lesagesander

Block or report user

Report or block lesagesander

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@lesagesander
lesagesander / changeTitle.cs
Created Dec 3, 2014
Changing Title metadata field of a document with REST
View changeTitle.cs
var updateMetadata =
String.Format("_api/web/lists/getByTitle(@TargetLibrary)/RootFolder/folders(@TargetFolderName)/files/getbyurl(url=@TargetFileName)/listitemallfields?" +
"@TargetLibrary='{0}'&@TargetFolderName='{1}'&@TargetFileName='{2}'", docLibName, folderName, fileName);
//2. Update title metadata field.
//prep rest call
url = new Uri(String.Format("{0}{1}", SpoAuthUtility.Current.SiteUrl, updateMetadata));
Console.WriteLine("\nREST Call updateMetadata: {0}\n\n", url);
//prep metadata changes.
@lesagesander
lesagesander / readAndUpload.cs
Created Dec 3, 2014
Reading and uploading a file with REST (c#)
View readAndUpload.cs
//read file
Console.Write("Enter file path: ");
var filePath = Console.ReadLine();
filePath = String.IsNullOrEmpty(filePath) ? "C:\\Users\\Sander\\Desktop\\test.docx" : filePath;
var byteArray = File.ReadAllBytes(filePath);
//prep REST endpoint
var addFileInFolder =
String.Format("_api/web/lists/getByTitle(@TargetLibrary)/RootFolder/folders(@TargetFolderName)/files/add(url=@TargetFileName,overwrite='{3}')?" +
"@TargetLibrary='{0}'&@TargetFolderName='{1}'&@TargetFileName='{2}'",docLibName, folderName, fileName, true);
View CreateAzureServiceBus.ps1
Add-AzureAccount
New-AzureSBNamespace -Name "Your namespace name" - Location "your location"
@lesagesander
lesagesander / Add ListViewWebPart to wiki page and adapt view.cs
Last active Aug 29, 2015
Add ListViewWebPart to wiki page and adapt view
View Add ListViewWebPart to wiki page and adapt view.cs
public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
{
var result = new SPRemoteEventResult();
using (var clientContext = TokenHelper.CreateRemoteEventReceiverClientContext(properties))
{
if (clientContext != null)
{
try
{
View Add ListViewWebPart to wiki page.cs
public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
{
var result = new SPRemoteEventResult();
// Get the token from the request header. Because this is a .svc remote event receiver we use the current Operationcontext.
var requestProperty = (HttpRequestMessageProperty)OperationContext.Current.IncomingMessageProperties[HttpRequestMessageProperty.Name];
var contextToken = TokenHelper.ReadAndValidateContextToken(requestProperty.Headers["X-SP-ContextToken"], requestProperty.Headers[HttpRequestHeader.Host]);
using (var clientContext = TokenHelper.CreateRemoteEventReceiverClientContext(properties))
{
View AppManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<!--Created:cb85b80c-f585-40ff-8bfc-12ff4d0e34a9-->
<App xmlns="http://schemas.microsoft.com/sharepoint/2012/app/manifest" Name="YourAppName" ProductID="{6b1a2b10-c511-4484-a0f2-d8d247e1c3e7}" Version="1.6.0.8" SharePointMinVersion="15.0.0.0">
<Properties>
<Title>YourAppName</Title>
<StartPage>https://localhost:44303/Pages/Default.aspx?{StandardTokens}&amp;SPHostTitle={HostTitle}</StartPage>
<UpgradedEventEndpoint>https://YourServiceBus.servicebus.windows.net/3458491647/3050950848/obj/f44563bb-02a0-4a5b-b2da-737023b5a03e/Services/AppEventReceiver.svc</UpgradedEventEndpoint>
<InstalledEventEndpoint>https://YourServiceBus.servicebus.windows.net/3458491647/3050950848/obj/f44563bb-02a0-4a5b-b2da-737023b5a03e/Services/AppEventReceiver.svc</InstalledEventEndpoint>
</Properties>
<AppPrincipal>
View create list and bind remote event receiver.cs
//do not forget to reference officeams.core (http://officeams.codeplex.com) dll to call extension methods.
//create settingslist
hostWebClientContext.Web.AddList(100, new Guid("00bfea71-de22-43b2-a848-c05709900100"), "Settings", false);
//get settings list
var settingsList = hostWebClientContext.Web.GetListByTitle("Settings");
//prepare eventreceiver binding
var eventReceivers = settingsList.EventReceivers;
View CSOM_CopyFile.js
function copyFile(targetSiteUrl, contextId, targetFileName, targetList) {
//get current search result item
var currentItem = window.ctxData[contextId];
// Create a request executor.
var sourceExecutor = new SP.RequestExecutor(currentItem.SPSiteUrl);
var targetExecutor = new SP.RequestExecutor(targetSiteUrl);
// Get the absolute server url.
var serverUrlRegex = new RegExp(/http(s?):\/\/([\w]+\.){1}([\w]+\.?)+/);
You can’t perform that action at this time.