Showing posts with label know-it. Show all posts
Showing posts with label know-it. Show all posts

Monday, March 14, 2016

Updating Publishing Page attribute in SharePoint Online

We have moved over to using the Patterns and Practices approach to SharePoint site deployment, with the exception of a few older or more complex .wsp based sites and for one product we are using post-provisioning tasks to modify the values of a custom content type based on values passed through PnP by storing them in the property bag.

Initially, the site template we were using was a vanilla Team Site, however, it was deemed necessary to enable publishing to achieve certain goals. Once this was done, we needed to checkin/checkout/publish the page in order to make and save the changes. This was failing with the save operation complaining that the page was checked out. Initially I was shouting at SP because I knew the page was checked out, because I had asked for it to be, however, it seems that this wasn't the checkout SP was referring to.

Finding this post on Stack Overflow (http://sharepoint.stackexchange.com/questions/59177/check-out-update-then-check-in-a-file-in-sharepoint-client-object-model) it seems that the flow needs to be:

  • Check out
  • ExecuteQuery()
  • Modify
  • Update()
  • ExecuteQuery()
  • Checkin
  • Publish
  • ExecuteQuery()
When we did this the page was successfully updated. One thing that I additionally did was to wrap the checkout/executequery in a try/catch so that if the page was already checked out, it would carry on and run the update. However, this will probably only be a solution if the user who has the page checked out is the same as that running the current update.

Thursday, March 10, 2016

PowerShell Script with full path

One of those banging your head one the wall problems today, with trying to run a PS script that I needed to supply the full path and where the path had spaces.

PS C:\>C:\My Scripts\My PowerShell.ps1

Now I knew that wouldn't work, but tried it anyway. Get the error

The term 'C:\My' is not recognized as the name of a cmdlet, function, script file, or operable program.

So I think, ok, let's wrap in quotes. That'll work

PS C:\>"C:\My Scripts\My PowerShell.ps1"

But nothing. No error, no nothing...hmmm

Some Googling later, as with PS scripts that don't need a space, you need to pre-fix with .\, if they are wrapped in quotes, you need to prefix with '&' (obviously). I expect it is obvious to those that work in PS all the time, but I don't...

So the command I was really looking for is

PS C:\>& "C:\My Scripts\My PowerShell.ps1"