从R上传文件到SharePoint

时间:2018-12-01 09:27:40

标签: r sharepoint

我正在尝试将文件从R上传到SharePoint。我发现了类似的问题,例如Saving files to SharePoint folder from RSaving a file to Sharepoint with RCopying file to sharepoint library in R,但是我无法让它自己运行。

到目前为止我尝试过的事情:

system("curl --ntlm --user username:password --upload-file file.xslx https://companyname.sharepoint.com/sites/sitename/Shared%20documents/file.xlsx")

system("curl --ntlm --user username:password --upload-file file.xslx https://companyname.sharepoint.com/sites/sitename/Documents/file.xlsx")

system("curl --ntlm --user username:password --upload-file file.xslx https://companyname.sharepoint.com/sites/sitename/Shared documents/file.xlsx")

system("curl --ntlm --user username:password --upload-file file.xslx \\\\companyname.sharepoint.com@SSL\\sites\\sitename\\Shared%20documents\\file.xlsx")

请注意,我们的SharePoint使用我们的母语(荷兰语),因此文件夹“共享文档”为“ Gedeelde documenten”。我尝试了两种语言,但没有成功。不确定我应该使用英文名称还是荷兰文名称。

我的猜测是我使用的网址格式不正确,所以我已经尝试过了,但是我自己却找不到正确的方式。 非常感谢您的帮助。

编辑:

这是Sharepoint中页面和文件夹的外观。 完整网址(从/ Forms猜测部分,直到命令中不需要结尾为止):https://companyname.sharepoint.com/sites/SiteName/Gedeelde%20documenten/Forms/AllItems.aspx?id=%2Fsites%2FOfficeSFMT%2FGedeelde%20documenten%2FGeneral%2FTest

文件夹的屏幕截图:foldernames

我最好的猜测是尝试:"--upload-file C:/Users/UserName/Documents/Test.txt", "companyname.sharepoint.com/sites/SiteName/Documenten/General/Test/Test.txt"

1 个答案:

答案 0 :(得分:0)

我刚刚测试了以下代码,它起作用了:

cmd <- paste("curl --max-time 7200 --connect-timeout 7200 --ntlm --user", "username:password",  "--upload-file Book1.xlsx","teamsites.companyname.com/sites/SandBox/Documents/UserDocumentation/Test/Book1.xlsx", sep = " ")
system(cmd)

我通常使用以下功能。但是,唯一的问题是传输的文件将保持“检出”状态,直到手动“检入”该文件供其他人使用为止。

saveToSharePoint <- function(fileName) 
  {
   cmd <- paste("curl --max-time 7200 --connect-timeout 7200 --ntlm --user","username:password", 
              "--upload-file /home/username/FolderNameWhereTheFileToTransferExists/",fileName, 
              "teamsites.OrganizationName.com/sites/PageTitle/Documents/UserDocumentation/FolderNameWhereTheFileNeedsToBeCopied/",fileName, sep = " ")
   system(cmd)
  }

 saveToSharePoint("SomeFileName.Ext")