Skip to main content

Save SharePoint list attachments to a folder

Here is a powershell script to save SharePoint list attachments to a folder

Add-PsSnapin Microsoft.SharePoint.PowerShell

function downloadListAttachments ( ){
[CmdletBinding()]
 Param(
  [Parameter(Mandatory=$True,Position=1)]
   [string]$siteURL,
   [Parameter(Mandatory=$True)]
   [string]$listName,
   [string]$Path

)

    
    $tempLocation = $Path      
    $w = Get-SPWeb $siteURL   
    $l = $w.Lists[$listName]    
    foreach ($listItem in $l.Items)
    {
          Write-Host "    Content: " $listItem.ID 
           $destinationfolder = $tempLocation         
           if (!(Test-Path -path $destinationfolder))        
                {            
                 $dest = New-Item $destinationfolder -type directory          
                }
           foreach ($attachment in $listItem.Attachments)    
           {     
               $attachment   
               $file = $w.GetFile($listItem.Attachments.UrlPrefix + $attachment)        
               $bytes = $file.OpenBinary()                
               $path = $destinationfolder + "\" + $attachment 
               Write "Saving $path" 
               $fs = New-Object System.IO.FileStream($path, "OpenOrCreate") 
               $fs.Write($bytes, 0 , $bytes.Length)    
               $fs.Close()    
           }
     }
 }
 
downloadListAttachments -siteURL "https://abc" -listName "ListName" -Path "C:\Temp"


Reference : http://bhatiaashish.blogspot.com.au/2012/08/powershell-script-to-download.html

Comments

Popular posts from this blog

SharePoint 2013 workflow : The server was unable to process the request

Here, I received another SharePoint 2013 workflow error.
This time the workflow was not able to send emails and the following error was being shown

Retrying last request. Next attempt scheduled in less than one minute. Details of last request: HTTP Unauthorized to http://sitename/_vti_bin/client.svc/web/lists/getbyid(guid'guid') Correlation Id: id Instance Id: id

Fortunately I came across this post which gave me the answer
http://sharepoint.stackexchange.com/questions/89101/failed-to-retrieve-the-com-class-factory-for-component-with-clsid-sp-sprequest

Solution 1:
In InetMgr, go to advanced settings for Security Token Service Application Pool and change "Load User Profile" to true. Recycle application pool.

Reason 2 and Solution 2 : There could be another reason for this error. The workflow authentication can fail if the user executing the workflow (this will be the user initiating the workflow) is given permission through active directory group and the container for t…

OWA not working after security update

Office web apps for SharePoint 2013 not working after security updates / server patching.

After installation of the following security patches, OWA stopped working there by causing issues with SharePoint 2013.

Details of ULS logs are provided below.

FarmStateReplicator.exe (0x0CD8)
Office Web Apps
Farm State

Error when trying to connect to Farm State Manager service: System.ServiceModel.EndpointNotFoundException: There was no endpoint listening at http:///farmstatemanager/FarmStateManager.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.ServicePoint.ConnectSocketInternal(Boolean con…

Sharepoint 2013 Workflow - something went wrong

When I try to run a worflow created using SharePoint 2013 designer, I get the following error:

"Something went wrong. To try again, reload the page and then start the workflow."





Resolution:

Restart these services:

Service Bus GatewayService Bus Message Broker

Edit the workflow in designer and republish.


ULS logs for reference:

Request ManagementHighReached maximum number of failed machines based on ping results for this routing groupRequest ManagementMediumMapping URI from 'http://siteCollection:80/_vti_bin/client.svc/ProcessQuery' to 'http://<SPAppServer>_vti_bin/client.svc/ProcessQuery'Logging Correlation DataMediumName=Request (POST:http://siteCollection/_vti_bin/client.svc/ProcessQuery)Authentication AuthorizationMediumNon-OAuth request. IsAuthenticated=True, UserIdentityName=0#.w|<userLoginName>, ClaimsCount=25CSOMMediumBegin CSOM Request ManagedThreadId=103, NativeThreadId=11660Logging Correlation DataMediumSite=/MicrofeedsHighserviceHost_Req…