If there is no action to Copy from file share, is it possible to upload documents with a webservice? If so, what webservice should I use?

  • 20 November 2015
  • 7 replies
  • 3 views

Badge +1

From SAP we will get lots of PDF-documents which we will have to publish in SharePoint.

The documents will be stored on the file system, so we have the challenge to get them in SharePoint.

Is there a way to get the files from the file system in SharePoint using a Nintex workflow?


7 replies

Userlevel 7
Badge +17

I used the NTX PowerShell Action - Stable Release​ to upload documents from a file share to my SharePoint site within a workflow. Could that help?

Badge +1

Your answer might help, but the problem is that we have no knowledge of PowerShell.

If you can provide us with the PowerShell script to use, it would be highly appreciated.

Userlevel 7
Badge +17

You can use the action to fill in the variables instead of hardcoding them.

# Set the variables

$WebURL = “http://portal.contoso.com/sites/stuff”

$DocLibName = “Docs”

$FilePath = “C:DocsstuffSecret Sauce.docx”

# Get a variable that points to the folder

$Web = Get-SPWeb $WebURL

$List = $Web.GetFolder($DocLibName)

$Files = $List.Files

# Get just the name of the file from the whole path

$FileName = $FilePath.Substring($FilePath.LastIndexOf(""")+1)

# Load the file into a variable

$File= Get-ChildItem $FilePath

# Upload it to SharePoint

$Files.Add($DocLibName +"/" + $FileName,$File.OpenRead(),$false)

$web.Dispose()

Userlevel 7
Badge +11

Here is a script that I have been using.. It could probably do with a tidy, but does the trick.. An important part for me was the ability to set field properties on the document once loaded.

Add-PSSnapin "Microsoft.SharePoint.PowerShell"
[Microsoft.SharePoint.SPSecurity]::RunWithElevatedPrivileges({

function UploadFileInLibrary           
{           
    [CmdletBinding()]           
    Param(           
    [Parameter(Mandatory=$true,ValueFromPipeline=$true)]           
    [string]$webUrl,           
    [Parameter(Mandatory=$true)]           
    [string]$DocLibName,           
    [Parameter(Mandatory=$true)]           
    [string]$FilePath           
    )                
             
    Start-SPAssignment -Global             
    $spWeb = Get-SPWeb -Identity $webUrl            
    $spWeb.AllowUnsafeUpdates = $true;           
    $List = $spWeb.Lists[$DocLibName]           
    $folder = $List.RootFolder           
    $FileName = $FilePath.Substring($FilePath.LastIndexOf(""")+1)            
    $File= Get-ChildItem $FilePath           
    [Microsoft.SharePoint.SPFile]$spFile = $spWeb.GetFile("/" + $folder.Url + "/" + $File.Name)           
    $flagConfirm = 'y'           
    if($spFile.Exists -eq $true)           
    {           
        $flagConfirm = Read-Host "File $FileName already exists in library $DocLibName, do you    want to upload a new version(y/n)?"            
    }           
               
    if ($flagConfirm -eq 'y' -or $flagConfirm -eq 'Y')           
    {           
        $fileStream = ([System.IO.FileInfo] (Get-Item $File.FullName)).OpenRead()           
        #Add file           
        write-host -NoNewLine -f yellow "Copying file " $File.Name " to " $folder.ServerRelativeUrl "..."           
        [Microsoft.SharePoint.SPFile]$spFile = $folder.Files.Add($folder.Url + "/" + $File.Name, [System.IO.Stream]$fileStream, $true)           
        write-host -f Green "...Success!"           
        #Close file stream           
        $fileStream.Close()           
        write-host -NoNewLine -f yellow "Update file properties " $spFile.Name "..." 

       #Update field properties. Add new line if needed before the Item.update
        $spFile.Item["Title"] = "{ItemProperty:Account_x0020_Name}"
        $spFile.Item["AccountNumber"] = "{ItemProperty:Title}"
        $spFile.Item.Update()           
        write-host -f Green "...Success!"           
    }              
    $spWeb.AllowUnsafeUpdates = $false;           
           
    Stop-SPAssignment -Global             
}

#Set Variables

$webUrl = "https://sharepoint.local/sites/team"           
$DocLibName = "Shared Documents"           
$filePath =  "C: eports{ItemProperty:Title}{ItemProperty:Title}{ItemProperty:farm}.PDF"            
UploadFileInLibrary $webUrl  $DocLibName $filePath })

Userlevel 7
Badge +11

This is a script that I have been using for a month or so without failure. One thing that did stump me for a while was because the PowerShell action connects remotely to the server the Sharepoint CMDLETS need to be run with elevated permissions.

E.G.

Add-PSSnapin "Microsoft.SharePoint.PowerShell"

[Microsoft.SharePoint.SPSecurity]::RunWithElevatedPrivileges({

SCRIPT

})

Badge +1

Andrew, thank you for trying to help me out, but people here don't want me to use PowerShell-script for this challenge.

Sorry for not responding sooner.

Badge

Hello,

I have a script that copy from file share to sharepoint folder. I tested the script in powershell and work's fine but when i put in Nintex workflow powershell i get the follow error:

system.Management.Automation.Remoting.PSRemotingTransportException: Connecting to remote server failed with the following error message : The WinRM client cannot process the request. CredSSP authentication is currently disabled in the client configuration. Change the client configuration and try the request again. CredSSP authentication must also be enabled in the server configuration.

 

But i already enable this winRM and psremoting.

 

There are another option to do this?

Reply