从远程计算机将文件上传并签入到 SharePoint
Upload and Check-in File to SharePoint from a Remote Machine
我正在尝试使用 Powershell 将文件上传和签入到 SharePoint Intranet 网站。此脚本将 运行 在远程计算机上,而不是托管站点的服务器上。在 instructions given here 之后上传文件相对容易。
下面是我用来上传文件的过程的一小部分。它们已成功上传,但仍由我签出。有没有办法在使用 Powershell 时检查这些文件?
$destination = "http://mycompanysite.com/uploadhere/Docs”
$File = get-childitem “C:\Docs\stuff\To Upload.txt”
# Upload the file
$webclient = New-Object System.Net.WebClient
$webclient.UseDefaultCredentials = $true
$webclient.UploadFile($destination + "/" + $File.Name, "PUT", $File.FullName)
不幸的是,无法使用 SharePoint PowerShell 模块,因为这是 运行 在远程计算机上。
谢谢!
使用 Microsoft.SharePoint.Client 可能会更轻松,您可以从此处下载:Download SharePoint Server 2013 Client Components
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" #loads sharepoint client runtime
$destination = "http://mycompanysite.com/uploadhere"
$listName = "Docs"
$context = New-Object Microsoft.SharePoint.Client.ClientContext($destination)
$context.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials #signs you in as the currently logged in user on the local host
$context.RequestTimeout = 10000000
$list = $context.Web.Lists.GetByTitle($listName)
$context.Load($list)
$context.ExecuteQuery()
$stream = New-Object IO.FileStream($File.FullName,[System.IO.FileMode]::Open)
$fileOptions = New-Object Microsoft.SharePoint.Client.FileCreationInformation
$fileOptions.Overwrite = $true
$fileOptions.ContentStream = $stream
$fileOptions.URL = $File
$upload = $list.RootFolder.Files.Add($fileOptions)
$context.Load($upload)
$context.ExecuteQuery()
$upload.CheckIn("My check in message", [Microsoft.SharePoint.Client.CheckinType]::MajorCheckIn) #other options can be looked at here: https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.checkintype.aspx
$context.ExecuteQuery() #finally save your checkin
我正在尝试使用 Powershell 将文件上传和签入到 SharePoint Intranet 网站。此脚本将 运行 在远程计算机上,而不是托管站点的服务器上。在 instructions given here 之后上传文件相对容易。
下面是我用来上传文件的过程的一小部分。它们已成功上传,但仍由我签出。有没有办法在使用 Powershell 时检查这些文件?
$destination = "http://mycompanysite.com/uploadhere/Docs”
$File = get-childitem “C:\Docs\stuff\To Upload.txt”
# Upload the file
$webclient = New-Object System.Net.WebClient
$webclient.UseDefaultCredentials = $true
$webclient.UploadFile($destination + "/" + $File.Name, "PUT", $File.FullName)
不幸的是,无法使用 SharePoint PowerShell 模块,因为这是 运行 在远程计算机上。
谢谢!
使用 Microsoft.SharePoint.Client 可能会更轻松,您可以从此处下载:Download SharePoint Server 2013 Client Components
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" #loads sharepoint client runtime
$destination = "http://mycompanysite.com/uploadhere"
$listName = "Docs"
$context = New-Object Microsoft.SharePoint.Client.ClientContext($destination)
$context.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials #signs you in as the currently logged in user on the local host
$context.RequestTimeout = 10000000
$list = $context.Web.Lists.GetByTitle($listName)
$context.Load($list)
$context.ExecuteQuery()
$stream = New-Object IO.FileStream($File.FullName,[System.IO.FileMode]::Open)
$fileOptions = New-Object Microsoft.SharePoint.Client.FileCreationInformation
$fileOptions.Overwrite = $true
$fileOptions.ContentStream = $stream
$fileOptions.URL = $File
$upload = $list.RootFolder.Files.Add($fileOptions)
$context.Load($upload)
$context.ExecuteQuery()
$upload.CheckIn("My check in message", [Microsoft.SharePoint.Client.CheckinType]::MajorCheckIn) #other options can be looked at here: https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.checkintype.aspx
$context.ExecuteQuery() #finally save your checkin