Skip to content
Microsoft Dynamics 365 CRM Tips and Tricks
By Inogic
  • Blogs
  • D365 Apps
  • Inogic
  • D365 / Power Platform Services
  • Maplytics Docs
  • D365 Apps Docs
    • Omnichannel Apps
      • WhatsApp4Dynamics
      • TextSMS4Dynamics
      • LiveChat4Dynamics
    • File and Storage Managment
      • Attach2Dynamics
      • SharePoint Security Sync
    • Visualization Apps
      • Map My Relationships
      • Kanban Board
      • Business Process Checklist
    • Productivity Apps
      • Click2Clone
      • Click2Export
      • Undo2Restore
      • Lead Assignment and Distribution Automation
      • Alerts4Dynamics
      • Translate4Dynamics
      • Subscription Recurring Billing Management
    • User Adoption Apps
      • DeDupeD
      • User Adoption Monitor
      • Gamifics365
    • Integration Apps
      • Marketing4Dynamics
      • InoLink

Set the metadata of a SharePoint file using REST

By Inogic | August 9, 2017
0 Comment

Introduction:

In our earlier blog, we discussed about creating folders and uploading files on the SharePoint Online through workflows/plugins using REST.

In this blog, we will see how we can set the metadata of the uploaded files using REST.

Below is the code snippet to set the metadata of a file using REST:

//Here first create the JSON string of file metadata
string result = @"{'__metadata': { 'type': 'SP.ListItem'}, 'Aliases':'My File.docx', 'Owner':'CRM Owner', 'Date':'1/7/2017'}";
string siteUrl = “https://crmtrial.sharepoint.com” 
Uri spSite = new Uri(siteUrl);
private SpoAuthUtility _spo = SpoAuthUtility.Create(spSite, _username, WebUtility.HtmlEncode(_password), false);
//read the digest
string digest = _spo.GetRequestDigest();
//convert JSON data to bytes
byte[] content = ASCIIEncoding.ASCII.GetBytes(result);

//define the file URL to set the metadata
string fileURL = Account/Test Account Folder/TestFile.docx;
var requestUrl = string.Format("{0}/_api/web/GetFileByServerRelativeUrl('{1}')/ListItemAllFields", siteURL, fileURL);

var webRequest = (HttpWebRequest)HttpWebRequest.Create(requestUrl);
                webRequest.Headers.Add("X-RequestDigest", digest);
                webRequest.Headers.Add("X-HTTP-Method", "PATCH");
                webRequest.Headers.Add("If-Match", "*");
                webRequest.Accept = "application/json;odata=verbose";
                webRequest.ContentType = "application/json;odata=verbose";
                webRequest.Method = "POST";

                // Send a json odata request to SPO rest services to fetch all list items for the list.
                byte[] result = HttpHelper.SendODataJsonRequest(
                  new Uri(requestUrl),
                  "POST", // reading data from SP through the rest api usually uses the GET verb 
                  content,
                  webRequest,
                  _spo // pass in the helper object that allows us to make authenticated calls to SPO rest services
                  );

                //read the response
                string response = Encoding.UTF8.GetString(result, 0, result.Length);

If you go to the uploaded file’s properties in SharePoint, you can see the metadata of the file as shown in the screenshot below;

Set the metadata of a SharePoint file using REST

Hope this helps!

Generate Your Own New Leads Within Microsoft Dynamics 365 CRM

Contact us for a demo to know more about how Maplytics can help you to generate new leads from within Microsoft Dynamics 365 CRM.

Maplytics is a 5-star rated, preferred business app on the Microsoft AppSource that is Certified for Microsoft Dynamics 365 (CfMD) and comes with powerful features like Appointment Planning, Sales Routing, Territory Management, Heat Maps, Geo-analytical Dashboards and more that empower organizations to add more value to their CRM data, improve sales & service processes, and achieve high ROI.

Get your free trial from our Website or Microsoft AppSource!

‘If data is the new oil, location intelligence is ??”

Category: Dynamics 365 Dynamics CRM SharePoint Tags: REST, Set the metadata of a SharePoint file, SharePoint
Post navigation
← Change the background of List Row dynamically in Resco Exporting and Sharing Dynamics 365 Reports Made Easy! →

Follow Us!

Follow Us on FacebookFollow Us on TwitterFollow Us on LinkedInFollow Us on YouTubeFollow Us on InstagramFollow Us on E-mailFollow Us on Docs

Blog Series

  • Power Apps – Model Driven Apps
  • Power Apps – Canvas App
  • Power Pages
  • Power Automate
  • Power BI
  • AI Builder
  • Copilot
  • Azure OpenAI
  • Microsoft Teams
  • Dynamics 365 for Field Service

Recent Innovations

Top Reasons your Dynamics 365 CRM Needs a Translation App today!

Guide to Branding Your Dynamics 365 Live Chat Integration App!

AI Meets WhatsApp in Dynamics 365

How to Track Mailchimp Customer Journey Email Insights in Dynamics 365 CRM?

Never Miss an Important CRM Alert Again: Introducing Snooze in Dynamics 365 Notifications

Top Questions About Dynamics 365 CRM Document & Storage Management—Answered!

Summer 2025 Dynamics 365 Maps Release: Smarter Routing, Azure Maps, Canvas Apps & More!

Detect and Merge Dynamics 365 CRM Duplicate Records with New DeDupeD Features!

Recent Posts

  • Streamline Lead Qualification with The Sales Qualification Agent in Dynamics 365
  • Building Translytical Flows in Power BI Reports
  • Dynamics 365 CRM Field Merge: A Smarter Way to Manage Duplicate Data!
  • How to Configure Generative AI Plugin in Copilot for Improved Customer Service
  • Connecting ESRI ArcGIS system to Dynamics 365 CRM with Maplytics!

Archives

SiteLock
Copyright © 2025 Inogic. All Rights Reserved
Iconic One Theme | Powered by Wordpress