Skip to content

Instantly share code, notes, and snippets.

Created December 3, 2014 12:32
What would you like to do?
Changing Title metadata field of a document with REST
var updateMetadata =
String.Format("_api/web/lists/getByTitle(@TargetLibrary)/RootFolder/folders(@TargetFolderName)/files/getbyurl(url=@TargetFileName)/listitemallfields?" +
"@TargetLibrary='{0}'&@TargetFolderName='{1}'&@TargetFileName='{2}'", docLibName, folderName, fileName);
//2. Update title metadata field.
//prep rest call
url = new Uri(String.Format("{0}{1}", SpoAuthUtility.Current.SiteUrl, updateMetadata));
Console.WriteLine("\nREST Call updateMetadata: {0}\n\n", url);
//prep metadata changes.
var body = String.Format("{{ '__metadata': {{ 'type': 'SP.ListItem' }}, 'Title': '{0}' }}", docTitle);
//prep headers for update metadata POST request
headers = new Dictionary<String, String> { { "X-RequestDigest", formDigest }, { "X-HTTP-Method", "MERGE" }, { "IF-MATCH", "*" } };
// Send a json odata request to SPO rest services to upload a file to a document library.
// pass in the helper object that allows us to make authenticated calls to SPO rest services
result = HttpHelper.SendODataJsonRequestString(
"POST", //writing data to SharePoint.
response = Encoding.UTF8.GetString(result, 0, result.Length);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment