Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

PowerBuilder Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
Secrets
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(PowerBuilder) SharePoint -- Download Newer Files

See more SharePoint Examples

Demonstrates how to download all files from a SharePoint folder that are newer than the local files.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

integer li_rc
oleobject loo_Http
oleobject loo_SbJson
integer li_Success
oleobject loo_Fac
oleobject loo_Json
integer li_NumFiles
oleobject loo_LastModRemote
oleobject loo_LastModLocal
oleobject loo_LocalPath
oleobject loo_FileUrl
integer i
string ls_Filename
string ls_SLastModified
integer li_BDownload
integer li_NumSeconds

// This requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

// -------------------------------------------------------------------------
// The following comments apply to SharePoint Windows classic authentication.
// -------------------------------------------------------------------------
// For example, imagine our SharePoint endpoint is https://xyzoffice.mycompany.com/
// The SHAREPOINT_NTLM_DOMAIN would be "mycompany.com"
// The SHAREPOINT_HTTPS_DOMAIN would be "xyzoffice.mycompany.com"
// Also, the SHAREPOINT_USERNAME would be just the name, not a full email address.
// for example, "chilkat" instead of "chilkat@mycompany.com"

loo_Http = create oleobject
// Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

// If SharePoint Windows classic authentication is used, then set the 
// Login, Password, LoginDomain, and NtlmAuth properties.
loo_Http.Login = "SHAREPOINT_USERNAME"
loo_Http.Password = "SHAREPOINT_PASSWORD"
loo_Http.LoginDomain = "SHAREPOINT_NTLM_DOMAIN"
loo_Http.NtlmAuth = 1

// -------------------------------------------------------------------------
// The more common case is to use SharePoint Online authentication (via the SPOIDCRL cookie).
// If so, do not set Login, Password, LoginDomain, and NtlmAuth, and instead
// establish the cookie as shown at SharePoint Online Authentication
// -------------------------------------------------------------------------

// First we'll download a list of all the files in the /Documents folder.
// This provides the names and last-modified date/times of the files located
// on the SharePoint server.
loo_Http.Accept = "application/json;odata=verbose"
loo_Http.AcceptCharset = "utf-8"

loo_SbJson = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbJson.ConnectToNewObject("Chilkat.StringBuilder")

li_Success = loo_Http.QuickGetSb("https://SHAREPOINT_HTTPS_DOMAIN/_api/web/GetFolderByServerRelativeUrl('/Documents')/Files",loo_SbJson)
if li_Success <> 1 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_SbJson
    return
end if

// Before proceeding, make sure the local directory where we'll be downloading files exists.
loo_Fac = create oleobject
// Use "Chilkat_9_5_0.FileAccess" for versions of Chilkat < 10.0.0
li_rc = loo_Fac.ConnectToNewObject("Chilkat.FileAccess")

loo_Fac.DirEnsureExists("qa_output/sharepoint/Documents")

// OK.. load the JSON and iterate over each file
loo_Json = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")

loo_Json.LoadSb(loo_SbJson)

li_NumFiles = loo_Json.SizeOfArray("d.results")
Write-Debug "Number of Files in the SharePoint /Documents folder = " + string(li_NumFiles)

loo_LastModRemote = create oleobject
// Use "Chilkat_9_5_0.CkDateTime" for versions of Chilkat < 10.0.0
li_rc = loo_LastModRemote.ConnectToNewObject("Chilkat.CkDateTime")

loo_LocalPath = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_LocalPath.ConnectToNewObject("Chilkat.StringBuilder")

loo_FileUrl = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_FileUrl.ConnectToNewObject("Chilkat.StringBuilder")

i = 0
do while i < li_NumFiles
    loo_Json.I = i

    ls_Filename = loo_Json.StringOf("d.results[i].Name")
    ls_SLastModified = loo_Json.StringOf("d.results[i].TimeLastModified")

    Write-Debug string(i + 1) + ": " + ls_Filename + " (" + ls_SLastModified + ")"

    loo_LastModRemote.SetFromTimestamp(ls_SLastModified)

    li_BDownload = 0
    // Check to see if the local file exists.  If not, then download.
    loo_LocalPath.SetString("qa_output/sharepoint/Documents/")
    loo_LocalPath.Append(ls_Filename)
    if loo_Fac.FileExists(loo_LocalPath.GetAsString()) <> 1 then
        Write-Debug "This file does not exist locally."
        li_BDownload = 1
    else
        // Get the local file's date time and compare with the remote file date/time.
        loo_LastModLocal = loo_Fac.GetLastModified(loo_LocalPath.GetAsString())
        if loo_Fac.LastMethodSuccess = 1 then
            // Get the difference in seconds between the local and remote last-modified times.
            // if the return value is negative, then the caller's time is 
            // older than the argument.  (in this case, a negative return value means
            // the local file is older than the remote file.

            // Note: The DiffSeconds method was found to be missing in the Chilkat .NET build
            // (and possibly in other builds). It will be present in the v9.5.0.67 release and later.
            li_NumSeconds = loo_LastModLocal.DiffSeconds(loo_LastModRemote)
            if li_NumSeconds < 0 then
                Write-Debug "The local file is older than the remote file."
                li_BDownload = 1
            end if

            destroy loo_LastModLocal
        else
            Write-Debug "Unable to get the local file's last-modified date/time."
            Write-Debug loo_Fac.LastErrorText
        end if

    end if

    if li_BDownload = 1 then
        loo_FileUrl.SetString("https://SHAREPOINT_HTTPS_DOMAIN/_api/web/GetFolderByServerRelativeUrl('/Documents')/Files('")
        loo_FileUrl.Append(ls_Filename)
        loo_FileUrl.Append("')/$value")

        Write-Debug "Downloading " + ls_Filename

        li_Success = loo_Http.Download(loo_FileUrl.GetAsString(),loo_LocalPath.GetAsString())
        if li_Success <> 1 then
            Write-Debug loo_Http.LastErrorText
            destroy loo_Http
            destroy loo_SbJson
            destroy loo_Fac
            destroy loo_Json
            destroy loo_LastModRemote
            destroy loo_LocalPath
            destroy loo_FileUrl
            return
        end if

        // Set the local file's last-modified date/time to that of the server's.
        loo_Fac.SetLastModified(loo_LocalPath.GetAsString(),loo_LastModRemote)

    end if

    i = i + 1
loop

Write-Debug "All finished."


destroy loo_Http
destroy loo_SbJson
destroy loo_Fac
destroy loo_Json
destroy loo_LastModRemote
destroy loo_LocalPath
destroy loo_FileUrl

 

© 2000-2024 Chilkat Software, Inc. All Rights Reserved.