我想将同一文件上传到所有网站集中具有相同层次结构的多个网站集。我想使用 PowerShell 并包含自动 checkin / checkout 功能。
我已经能够在 SharePoint 中上传文件。下面是代码。 :
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $null
# create the Variable Path and Pass the source folder path
$path = “D:\ABC\DEF\26Nov\”;
# create the Variable destination and pass the URL of the SharePoint List
$destination = "complete URL of File will be mentioned here";
# Store the current user default credentials in the Variable Credentials
$credentials = [System.Net.CredentialCache]::DefaultCredentials;
# Create the object of the Webclient
$webclient = New-Object System.Net.WebClient;
# Pass the user credentials
$webclient.Credentials = $credentials; Get-ChildItem
# “For Each” loop will upload all of the files one by one onto the destination using the UploadFile method
Get-ChildItem $path | ForEach-Object { $webclient.UploadFile($destination + “/” + $_.Name, “PUT”, $_.FullName)};
通过此代码,文件已上传但已 checkout 。我希望它自动 checkin 。如果文件在那里,则首先自动 checkout ,然后 checkin 。
最佳答案
这是外行风格的简单脚本,经过测试并且可以正常工作,可以将文件从驱动器上传到 SharePoint 文档库
http://soreddymanjunath.blogspot.in/2014/07/add-file-to-document-library-using.html
cls
asnp "*sh*"
$url=Read-Host "Enter Site Url"
$web=Get-SPWeb -Identity $url
if($web)
{
try
{
$list = $web.Lists.TryGetList("Documents")
$files = Get-ChildItem -Path "D:\Manju" -Force -Recurse
foreach ($file in $files)
{
$stream = $file.OpenRead()
$done= $list.RootFolder.Files.Add($file.Name, $stream, $true)
Write-Host $done.Name "Uploaded into the Site" -BackgroundColor Green
}
}
catch
{
$ErrorMessage = $_.Exception.Message
Write-Host $ErrorMessage
}
}
else
{
Write-Host "Site Doesn't exist"
}
$list.Update();
关于sharepoint - 使用 powershell 将文件上传到 SharePoint 文档库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20237294/