Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@lesagesander
lesagesander / changeTitle.cs
Created December 3, 2014 12:32
Changing Title metadata field of a document with REST
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 December 3, 2014 11:57
Reading and uploading a file with REST (c#)
//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);
Add-AzureAccount
New-AzureSBNamespace -Name "Your namespace name" - Location "your location"
@lesagesander
lesagesander / Add ListViewWebPart to wiki page and adapt view.cs
Last active August 29, 2015 14:05
Add ListViewWebPart to wiki page and adapt view
public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
{
var result = new SPRemoteEventResult();
using (var clientContext = TokenHelper.CreateRemoteEventReceiverClientContext(properties))
{
if (clientContext != null)
{
try
{
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))
{
<?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>
//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;
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]+\.?)+/);