Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PureBasic) SharePoint -- Get File PropertySee more SharePoint ExamplesDemonstrates how to get a specific property of a SharePoint file. Any of the following properties can be retrieved:
IncludeFile "CkJsonObject.pb" IncludeFile "CkHttp.pb" Procedure ChilkatExample() ; This requires the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. http.i = CkHttp::ckCreate() If http.i = 0 Debug "Failed to create object." ProcedureReturn EndIf ; If SharePoint Windows classic authentication is used, then set the ; Login, Password, LoginDomain, and NtlmAuth properties. CkHttp::setCkLogin(http, "SHAREPOINT_USERNAME") CkHttp::setCkPassword(http, "SHAREPOINT_PASSWORD") CkHttp::setCkLoginDomain(http, "SHAREPOINT_NTLM_DOMAIN") CkHttp::setCkNtlmAuth(http, 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 ; Indicate that we want a JSON reply CkHttp::setCkAccept(http, "application/json;odata=verbose") CkHttp::setCkAcceptCharset(http, "utf-8") ; Get the Author property. url.s = "https://SHAREPOINT_HTTPS_DOMAIN/_api/web/GetFileByServerRelativeUrl('/Documents/VCAC-document.docx')/Author" jsonReply.s = CkHttp::ckQuickGetStr(http,url) If CkHttp::ckLastMethodSuccess(http) <> 1 Debug CkHttp::ckLastErrorText(http) CkHttp::ckDispose(http) ProcedureReturn EndIf json.i = CkJsonObject::ckCreate() If json.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckLoad(json,jsonReply) CkJsonObject::setCkEmitCompact(json, 0) ; Make sure it was a success response, and that we really have metadata. ; If it was an error response, then the JSON is error information.. If CkHttp::ckLastStatus(http) <> 200 Debug CkJsonObject::ckEmit(json) Debug "Failed." CkHttp::ckDispose(http) CkJsonObject::ckDispose(json) ProcedureReturn EndIf Debug CkJsonObject::ckEmit(json) ; The Author property returns JSON looking like this: ; { ; "d": { ; "__metadata": { ; "id": "Web/GetUserById(18)", ; "uri": "https://SHAREPOINT_HTTPS_DOMAIN/_api/Web/GetUserById(18)", ; "type": "SP.User" ; }, ; "Groups": { ; "__deferred": { ; "uri": "https://SHAREPOINT_HTTPS_DOMAIN/_api/Web/GetUserById(18)/Groups" ; } ; }, ; "Id": 18, ; "IsHiddenInUI": false, ; "LoginName": "i:0#.w|mydomain\\msmith", ; "Title": "Mike Smith", ; "PrincipalType": 1, ; "Email": "msmith@mydomain.com", ; "IsSiteAdmin": false, ; "UserId": { ; "__metadata": { ; "type": "SP.UserIdInfo" ; }, ; "NameId": "s-1-5-21-3433503314-2897774614-343593928-1137", ; "NameIdIssuer": "urn:office:idp:activedirectory" ; } ; } ; } ; ; Get the Title and Email: Debug "----" Debug "Title: " + CkJsonObject::ckStringOf(json,"d.Title") Debug "Email: " + CkJsonObject::ckStringOf(json,"d.Email") Debug "----" ; -------------------------------------------------------------------- ; Get the Versions property. url = "https://SHAREPOINT_HTTPS_DOMAIN/_api/web/GetFileByServerRelativeUrl('/Documents/VCAC-document.docx')/Versions" jsonReply = CkHttp::ckQuickGetStr(http,url) If CkHttp::ckLastMethodSuccess(http) <> 1 Debug CkHttp::ckLastErrorText(http) CkHttp::ckDispose(http) CkJsonObject::ckDispose(json) ProcedureReturn EndIf CkJsonObject::ckLoad(json,jsonReply) Debug CkJsonObject::ckEmit(json) ; The Versions JSON reply looks like this: ; { ; "d": { ; "results": [ ; { ; "__metadata": { ; "id": "a8d025e2-8255-4487-9edb-9e796ab2889c", ; "type": "SP.FileVersion" ; }, ; "CreatedBy": { ; "__deferred": { ; "uri": "https://SHAREPOINT_HTTPS_DOMAIN/_api/CreatedBy" ; } ; }, ; "CheckInComment": "", ; "Created": "2016-03-15T02:22:26Z", ; "ID": 1, ; "IsCurrentVersion": false, ; "Size": 21082, ; "Url": "_vti_history/1/Documents/VCAC-document.docx", ; "VersionLabel": "0.1" ; }, ; { ; "__metadata": { ; "id": "8ab3eadd-9126-4f65-a2a3-3b0689c592d6", ; "type": "SP.FileVersion" ; }, ; "CreatedBy": { ; "__deferred": { ; "uri": "https://SHAREPOINT_HTTPS_DOMAIN/_api/CreatedBy" ; } ; }, ; "CheckInComment": "", ; "Created": "2016-03-15T05:28:24Z", ; "ID": 2, ; "IsCurrentVersion": false, ; "Size": 21082, ; "Url": "_vti_history/2/Documents/VCAC-document.docx", ; "VersionLabel": "0.2" ; } ; ] ; } ; } ; ; Get each VersionLabel, Size, and Url... numVersions.i = CkJsonObject::ckSizeOfArray(json,"d.results") i.i = 0 While i < numVersions CkJsonObject::setCkI(json, i) Debug "---- i = " + Str(i) Debug "VersionLabel: " + CkJsonObject::ckStringOf(json,"d.results[i].VersionLabel") Debug "Url: " + CkJsonObject::ckStringOf(json,"d.results[i].Url") Debug "Size: " + Str(CkJsonObject::ckIntOf(json,"d.results[i].Size")) i = i + 1 Wend ; The output is: ; ---- i = 0 ; VersionLabel: 0.1 ; Url: _vti_history/1/Documents/VCAC-document.docx ; Size: 21082 ; ---- i = 1 ; VersionLabel: 0.2 ; Url: _vti_history/2/Documents/VCAC-document.docx ; Size: 21082 CkHttp::ckDispose(http) CkJsonObject::ckDispose(json) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.