【问题标题】:Upload and Check-in File to SharePoint from a Remote Machine从远程计算机上载和签入文件到 SharePoint
【发布时间】:2017-03-16 23:03:38
【问题描述】:

我正在尝试使用 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 模块。

谢谢!

【问题讨论】:

    标签: powershell sharepoint sharepoint-2010


    【解决方案1】:

    使用 Microsoft.SharePoint.Client 可能会更轻松,您可以从此处下载:Download SharePoint Server 2013 Client Components

    Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
    Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\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
    

    【讨论】:

    • 抱歉没有早点回来。这正是我最终使用的解决方案。出于某种原因,使用 REST/oData 我一直遇到权限问题。
    猜你喜欢
    • 2012-07-09
    • 1970-01-01
    • 1970-01-01
    • 2010-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多