1

I'm trying to unpublish the last published version of a file(Page) when there is a draft version of it.

It is possible with OOTB UI.

SPFile.TakeOffline (Server Object Model) method can be used to do this. I'm looking for a CSOM (Client Object Model) equivalent for this method or fill the requirement.

Below is the OOTB behavior.

Unpublish 1.0 when there is a 1.1

1.0 becomes 0.2 when unpublished.

enter image description here

Requirement: Unpublish the last Major/Published file Version when there is a Draft version of it.

Update:

<site url>/_api/web/getfilebyserverrelativeurl(<relative file  path>)/unpublish(comment='done')

gives below error because there is a draft version at last.

“You can only Unpublish a major version or approved document. Or Cancel publish for a pending document.”

Even File.UnPublish CSOM gave the same error.

1

You can try the following solution.

CSOM: File.UnPublish

JS CSOM: SP.File.unPublish

REST Endpoint:

/_api/web/getfilebyserverrelativeurl('/Shared Documents/filename.docx')/unpublish(comment='done')
  • Hi, thanks for reply. <web url>/_api/web/getfilebyserverrelativeurl(<file path>)/unpublish(comment='done'). gives “You can only Unpublish a major version or approved document. Or Cancel publish for a pending document.” error because there is draft version at last. – MKEF Aug 1 '17 at 5:15
0

This is what finally worked for me, let me know if there is any alternative. After failing all CSOM approach, used fiddler and monitored the click action of "Unpublish this version" in view version history dialog window.(Click on the down arrow in the last published major version)

This is the POST request

<siteUrl>/_layouts/15/versions.aspx?FileName=%2Fsites%2<subSite>%2FPages%2F<myFile>%2Easpx&list={73076BC8-EF62-44DD-AA6A-2004B56998C9}&ID=44&col=Number&order=d&Source=http%3A%2F%2F<siteUrl>%2Fsites%2F<subSite>%2F<library>%2FForms%2F<viewName>%2Easpx&op=TakeOffline&IsDlg=1

It is passing some query string parameters to

<siteUrl>/_layouts/15/versions.aspx

Query string params

  • FileName = file name (URL Encoded)
  • list => list Id
  • ID => Item Id
  • col
  • order
  • Source => Request page (I was on 'All Documents' view)
  • op => Operation (TakeOffline)
  • IsDlg => is a dialog

I triggered this HTTP POST request from my code(JavaScript) it worked as I expected. It Unpublished the last published major version when there is a draft version.

Before

Before Execution

After Unpublishing 1.0 it became 0.2

After Unpublishing 1.0 it became 0.2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.