cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
awin
Nintex Newbie

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?

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?

Tags (3)
Reply
6 Replies
Automation Master
Automation Master

Re: 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?

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?

Reply
awin
Nintex Newbie

Re: 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?

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.

0 Kudos
Reply
Automation Master
Automation Master

Re: 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?

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:\Docs\stuff\Secret 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()

Reply
dan_stoll
Nintex Newbie

Re: 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?

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:\reports\{ItemProperty:Title}\{ItemProperty:Title}{ItemProperty:farm}.PDF"            
UploadFileInLibrary $webUrl  $DocLibName $filePath })

Reply
dan_stoll
Nintex Newbie

Re: 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?

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

})

Reply
awin
Nintex Newbie

Re: 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?

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.

0 Kudos
Reply