0

Here is my document library looks like. I have 2 content types with my document library. 1 content type is based on Document and the other content type is based on "Link to a document" type.

I am trying to upload some files using powershell script. I am using a csv file to read line by line and upload files to document library. I am getting error on $i.fileNameASPX. Powershell tells me that Missing expression after , . So what to do.

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      
}
3
  • Is ur $itemUrl a typo? Suppose to be New-Object right?? Commented Jul 2, 2012 at 20:18
  • Oh yeah. that too. but it's stuck at the $newfile the 4th line from the top. I think UTF8Enconding is supposed to be different format. Commented Jul 2, 2012 at 22:04
  • 1
    This seems like a duplicate post to: stackoverflow.com/questions/11304002/… I responded to the other post Commented Jul 3, 2012 at 13:14

1 Answer 1

2

Here is the Simple PowerShell script to upload files to a document library in SharePoint2013

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();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.