Chilkat HOME Android™ Classic ASP C C++ C# Mono C# .NET Core C# C# UWP/WinRT DataFlex Delphi ActiveX Delphi DLL Visual FoxPro Java Lianja MFC Objective-C Perl PHP ActiveX PHP Extension PowerBuilder PowerShell PureBasic CkPython Chilkat2-Python Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ Visual Basic 6.0 VB.NET VB.NET UWP/WinRT VBScript Xojo Plugin Node.js Excel Go
(MFC) SharePoint -- Get File PropertyDemonstrates how to get a specific property of a SharePoint file. Any of the following properties can be retrieved:
#include <CkHttp.h> #include <CkJsonObject.h> void ChilkatSample(void) { CkString strOut; // This requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. CkHttp http; // If SharePoint Windows classic authentication is used, then set the // Login, Password, LoginDomain, and NtlmAuth properties. http.put_Login("SHAREPOINT_USERNAME"); http.put_Password("SHAREPOINT_PASSWORD"); http.put_LoginDomain("SHAREPOINT_NTLM_DOMAIN"); http.put_NtlmAuth(true); // 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 http.put_Accept("application/json;odata=verbose"); // Get the Author property. const char *url = "https://SHAREPOINT_HTTPS_DOMAIN/_api/web/GetFileByServerRelativeUrl('/Documents/VCAC-document.docx')/Author"; const char *jsonReply = http.quickGetStr(url); if (http.get_LastMethodSuccess() != true) { strOut.append(http.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } CkJsonObject json; json.Load(jsonReply); json.put_EmitCompact(false); // 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 (http.get_LastStatus() != 200) { strOut.append(json.emit()); strOut.append("\r\n"); strOut.append("Failed."); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } strOut.append(json.emit()); strOut.append("\r\n"); // 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: strOut.append("----"); strOut.append("\r\n"); strOut.append("Title: "); strOut.append(json.stringOf("d.Title")); strOut.append("\r\n"); strOut.append("Email: "); strOut.append(json.stringOf("d.Email")); strOut.append("\r\n"); strOut.append("----"); strOut.append("\r\n"); // -------------------------------------------------------------------- // Get the Versions property. url = "https://SHAREPOINT_HTTPS_DOMAIN/_api/web/GetFileByServerRelativeUrl('/Documents/VCAC-document.docx')/Versions"; jsonReply = http.quickGetStr(url); if (http.get_LastMethodSuccess() != true) { strOut.append(http.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } json.Load(jsonReply); strOut.append(json.emit()); strOut.append("\r\n"); // 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... int numVersions = json.SizeOfArray("d.results"); int i = 0; while (i < numVersions) { json.put_I(i); strOut.append("---- i = "); strOut.appendInt(i); strOut.append("\r\n"); strOut.append("VersionLabel: "); strOut.append(json.stringOf("d.results[i].VersionLabel")); strOut.append("\r\n"); strOut.append("Url: "); strOut.append(json.stringOf("d.results[i].Url")); strOut.append("\r\n"); strOut.append("Size: "); strOut.appendInt(json.IntOf("d.results[i].Size")); strOut.append("\r\n"); i = i + 1; } // 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 SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); } |
© 2000-2022 Chilkat Software, Inc. All Rights Reserved.