Emmanuel Hamel
Emmanuel Hamel

Reputation: 2233

How to download the history of a Word file in Sharepoint using R

I would like to download the history of a Word file located in a SharePoint Online. Do you have an approach to propose?

Upvotes: 0

Views: 29

Answers (1)

Emmanuel Hamel
Emmanuel Hamel

Reputation: 2233

I have been able to download the history of a Word file that is located in a SharePoint Online with the following R code. The file has 50 versions.

library(RDCOMClient)
library(openxlsx)

versions <- 1 : 50
nb_Version <- length(versions)
dir_To_Save_File <- "C:\\Downloads\\"
list_Info <- list()

for(i in 1 : nb_Version)
{ 
  print(i)
  url <- paste0("https://XXXX.sharepoint.com/.../.../_vti_history/", i, "/.../my_Word_File.docx")
  doc <- wordApp[["Documents"]]$Open(url)
  date <- openxlsx::convertToDateTime(doc$BuiltinDocumentProperties("Last Save Time")$Value())
  date <- stringr::str_replace_all(date, ":|-", "_")
  author <- doc$BuiltinDocumentProperties("Last Author")$Value()
  list_Info[[i]] <- list(author = author, date, url = url)
  path_Save_File <- paste0(dir_To_Save_File, "Version_", i, "_Author_", author, "_Date_", date, "_my_Word_File.docx")
  doc$SaveAs(path_Save_File)
}

With the code above, I have been able to download the 50 versions of the specific Word file.

Upvotes: 2

Related Questions