0

这是我的文档库的样子。我的文档库有 2 种内容类型。一种内容类型基于文档,另一种内容类型基于“链接到文档”类型。

我正在尝试使用 powershell 脚本上传一些文件。我正在使用 csv 文件逐行读取并将文件上传到文档库。我在 $i.fileNameASPX 上遇到错误。Powershell 告诉我 , 之后缺少表达式。那么该怎么办。

if($i.ContentType = "LegalLink2Document")
{
    $itemType = $docLibrary.ContentTypes[$i.ContentType]
    $newFile = $docLibrary.RootFolder.Files.Add($i.fileNameASPX, UTF8Encoding.UTF8.GetBytes(builder.ToString()), $true) 
    $theItem = $newFile.Item
    $theItem["ContentTypeId"] = $itemType.Id
    $itemUrl = ew-object Microsoft.SharePoint.SPFieldUrlValue()
    $itemUrl.Url = $i.fileLinkUrl
    $itemUrl.Descrition = $i.URLDESC
    $theItem["URL"] = $itemUrl      
}
4

1 回答 1

2

这是用于将文件上传到 SharePoint2013 中的文档库的简单 PowerShell 脚本

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:\M" -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();
于 2014-07-24T10:08:52.583 回答