从 R 上传文件到 SharePoint [英] Uploading files to SharePoint from R

查看:53
本文介绍了从 R 上传文件到 SharePoint的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将文件从 R 上传到 SharePoint.我发现了类似的问题,例如

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

解决方案

我刚刚测试了以下代码,并且有效:

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 = "")系统(命令)

我经常使用以下功能.但是,唯一的问题是传输的文件将保持签出"状态,直到文件被手动签入"以供其他人使用.

saveToSharePoint <- 函数(文件名){cmd <- paste("curl --max-time 7200 --connect-timeout 7200 --ntlm --user","username:password","--upload-file", paste0("/home/username/FolderNameWhereTheFileToTransferExists/",fileName),paste0("teamsites.OrganizationName.com/sites/PageTitle/Documents/UserDocumentation/FolderNameWhereTheFileNeedsToBeCopied/",fileName), sep = ";")系统(命令)}saveToSharePoint("SomeFileName.Ext")

I am trying to upload a file from R to SharePoint. I have found similar questions like Saving files to SharePoint folder from R, Saving a file to Sharepoint with R and Copying file to sharepoint library in R but I haven't been able to get it working for myself.

The things I tried so far:

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")

Note that our SharePoint is in our native language (Dutch), so the folder "Shared documents" is "Gedeelde documenten". I tried both languages but without success. Not sure if I am supposed to the English names or the Dutch ones.

My guess is that the url I use is not in the correct format or such, so I have played around with that but can't come up with the correct way myself. Any help is much appreciated.

EDIT:

This is how the page and folder in Sharepoint looks like. Full url (guessed the part from /Forms till the end is not needed in the command): https://companyname.sharepoint.com/sites/SiteName/Gedeelde%20documenten/Forms/AllItems.aspx?id=%2Fsites%2FOfficeSFMT%2FGedeelde%20documenten%2FGeneral%2FTest

Screenshot of the folder:

My best guess was trying: "--upload-file C:/Users/UserName/Documents/Test.txt", "companyname.sharepoint.com/sites/SiteName/Documenten/General/Test/Test.txt"

解决方案

I just tested the following code and it worked:

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)

I routinely use the following function.However, the only issue will be the file that was transferred will remain 'checked-out' until the File is manually 'checked-in' for others to use.

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

 saveToSharePoint("SomeFileName.Ext")

这篇关于从 R 上传文件到 SharePoint的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆