【问题标题】:adding file to document library将文件添加到文档库
【发布时间】:2012-07-03 06:07:42
【问题描述】:

这是我的文档库的样子。我的文档库有 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      
}

【问题讨论】:

  • 你的 $itemUrl 是错字吗?假设是New-Object吧??
  • 哦,是的。那也是。但它卡在 $newfile 从顶部的第 4 行。我认为 UTF8Enconding 应该是不同的格式。
  • 这似乎是一个重复的帖子:stackoverflow.com/questions/11304002/…我回复了另一个帖子

标签: powershell sharepoint-2010 document-library


【解决方案1】:

这是在 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();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-11
    • 2011-09-07
    • 2018-05-30
    • 1970-01-01
    • 2017-11-18
    相关资源
    最近更新 更多