2017-04-23 44 views
1

我使用这个文件上传到SharePoint网站:在HTTPS网站创建目录

$sourcefile = "Reportdate.htm" 
$sourceFilePath = "D:\$sourcefile" 
$siteAddress = "https://Sharepoint.mysite.com/Reports" 
$urlDest = "{0}/{1}" -f ($siteAddress, $sourceFile) 
$webClient = New-Object System.Net.WebClient 
$WebClient.Credentials = [System.Net.CredentialCache]::DefaultCredentials 
$webClient.UploadFile($urlDest, "PUT", $sourceFilePath) 

我想组织中按日期的新目录下上传的文件,我不能找到一种方法来自动创建新建文件夹。

搜索Google等,显示如何通过FTP做到这一点,但这是不可用的。如果我可以使用其他方法自动创建文件夹,安装SharePoint管理单元并不可取。

+1

AFAIK这是不可能最终脚本检查使用PUT创建文件夹。它需要在服务器上使用Sharepoint API,ftp,PowerShell远程处理,创建一个可以调用的web服务+++ –

回答

0

发现这个网站有答案:

http://jleland.blogspot.com/2010/01/create-directories-and-upload-files-to.html

$url = "https://Sharepoint.mysite.com/Reports/Reports/$date" 
$req = [System.Net.HttpWebRequest]::Create($url) 
$req.Credentials = [System.Net.CredentialCache]::DefaultCredentials 
$req.Method = "MKCOL" 
$res = $req.GetResponse() 

所以我如果新的路径存在,如果不创建它

$url = "https://Sharepoint.mysite.com/Reports/Reports/$date" 
$check = ((wget $url -UseDefaultCredentials -ea 0).statuscode) 
If ($check -ne "200") { 
$req = [System.Net.HttpWebRequest]::Create($url) 
$req.Credentials = [System.Net.CredentialCache]::DefaultCredentials 
$req.Method = "MKCOL" 
$req.GetResponse() 
}