Posts

Showing posts from July, 2014

JQuery-Upload: unexpected token

While working with the JQuery-Upload control, I encountered the following error: unexpected token < The real kicker was the fact that my target file was still being created. The cause of the problem (as I eventually discovered) was my REST contract; my endpoint as configured as follows: [OperationContract] [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.WrappedResponse, UriTemplate = "/file/upload")] StatusData Upload(Stream fileData); but my endpoint was returning a JSON response. This resulted in a mismatch, as the expected response format was XML. Changing the contract to Json resolved the problem.

JQuery-Upload - a few ways to upload a file

I was recently using the magnificent  jQuery-File-Upload  in a SharePoint 2010 application. I encountered the following scenarios to upload files. 1. Load immediately when the file is selected This is the easiest option and is pretty much OOTB. $('#fileupload').fileupload({                 dataType: 'json',                 headers: {                     Accept: "application/json"                 },                 accept: 'application/json',                 formData: {                     url: "http://mytargetlocation",                     title: "myTitle"                 },                 done: function (e, data) {                     success();                 }             }); 2. Defer load until a button is checked This code will attach the 'submit' processing to the click event of a button with the ID 'btnSave' <input id="btnSave" type="submit" >  $('#fileup

Powershell: How do I execute a script in a new Powershell instance?

The great thing about PS is that is caches its objects for reuse. The bad thing about PS is that is caches its objects for reuse. Sometimes, scripts need to be executed in their own PS instances in order to avoid any changed data. Here is a simple example of a wrapper script (wrapper.ps1) that executes another script (test.ps1) in the same folder. The test script open notepad with the SchemaXml of a document library. Wrapper.ps1: function Get-ScriptDirectory  {   $Invocation = (Get-Variable MyInvocation -Scope 1).Value   Split-Path $Invocation.MyCommand.Path  }  $dir = Get-ScriptDirectory cd "$dir" powershell.exe "& `"$dir\test.ps1`" " Test.ps1: function AddSharePointSnapin([bool] $addSnapin) {     $sharePointSnapinName = "Microsoft.SharePoint.PowerShell"     If ($addSnapin)     {         Write-Host "Adding $sharePointSnapinName Snapin ..."         Add-PSSnapin $sharePointSnapinName -

Powershell; Write a file and open it

I have found this code quite helpful in debugging - especially trying to look through a large xml schema file for a SharePoint list. $fileName = "myFile.txt" # Write some variable property to a file $web = Get-SPWeb "http://blah.com" $list = $web.Lists["My List"] $list.SchemaXml > $fileName # Open the file in notepad  Start-Process notepad  -ArgumentList $fileName

SharePoint 2010: No item exists at http://site?ID=1. It has be been deleted by another user.

What the heck? I added a query string parameter to pass a value to a REST API and my solution exploded. Fortunately, there is a simple solution provided by our friends at Microsoft (see here ). It seems that the querystring parameter 'ID' is reserved, so renaming it to something else (in my case, docid) resolved the problem.

PowerShell: How do I run a Timer Service job?

This is an easy one liner: Get-SPTimerJob | Where-Object { $_.Name -like "*My Timer Service*" } | Start-SPTimerJob