将文件添加到文档库

时间:2012-07-02 19:51:56

标签: powershell sharepoint-2010 document-library

这是我的文档库的样子。我的文档库有2种内容类型。 1内容类型基于Document,而其他内容类型基于“链接到文档”类型。

我正在尝试使用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      
}

1 个答案:

答案 0 :(得分:2)

以下是将文件上载到SharePoint2013

中的文档库的Simple 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();
相关问题