0

I want to add video files to the Asset Library programmatically using powershell and Kindly help me. I tried the below code :

 Add-PSSnapIn Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 $sitecollecURL ="http://sirvr1:123/sites/enggtest"
 $videoFolderPath = "C:\Myvideofolder\"
 $videoLibFiles = Get-ChildItem $videoFolderPath -Include      
 *.wmv,*.mp3,*.mp4,*.flv,*.avi -Recurse 
 Write-Host -ForegroundColor Yellow "starting to add video  item to the asset  
 library " $sitecollecURL
 $siteDiscipline = Get-SPSite $sitecollecURL

My idea is to get the different video or audio files kept in the folder and read one by one which matches the extension and upload into the assets library

0

Your collection of files will be now stored in the below variable

 $videoLibFiles = Get-ChildItem $videoFolderPath -Include *.wmv,*.mp3,*.mp4,*.flv,*.avi -Recurse

Now loop through the variable $videoLibFiles to get the full file path and provide it as an input to uploading files to library

    foreach($filepath in $videoLibFiles)
{
$filepath.FullName
//Code to upload files

}

Please use this link to add files to assets library : Add file to library

  • Mark it as answer if you find it as the solution. Thanks. – Arvi Mar 2 '15 at 11:37
  • i got an error like given below:Exception calling "GetFile" with "1" argument(s): "Value does not fall within the expected range." At C:\videoScripts\AddVideostoDocLibwithConfirmation.ps1:36 char:5 + [Microsoft.SharePoint.SPFile]$spFile = $spWeb.GetFile("/" + $folder.Url + "/ ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : ArgumentException – userAZLogicApps Mar 2 '15 at 12:39
  • when i am trying to run this linje of code it gave me error [Microsoft.SharePoint.SPFile]$spFile = $folder.Files.Add($folder.Url + "/" + $File.Name, [System – userAZLogicApps Mar 2 '15 at 13:06
  • Can you share your script so that it will be easier to identify the issue ? – Arvi Mar 3 '15 at 4:38
  • Start-SPAssignment -Global $webUrl = "sRVR1:123/sites/ENGGtest" $FilePath ="C:\Maddy\Scripts\Wildlife.wmv" $spWeb = Get-SPWeb -Identity $webUrl $spWeb.AllowUnsafeUpdates = $true; $List = $spWeb.Lists["VideoLib"] $folder = $List.RootFolder $FileName = $FilePath.Substring($FilePath.LastIndexOf("\")+1) $File= Get-ChildItem $FilePath Write-Host $File [Microsoft.SharePoint.SPFile]$spFile = $spWeb.GetFile("/" + $folder.Url + "/" + $File.Name) – userAZLogicApps Mar 3 '15 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.