Update: Use the below code to update metadata without creating a new version.
- CheckOut the file before updating metadata and then check-in by overwriting the check-in parameter.
uploadedFile.CheckOut();
ListItem item = uploadedFile.ListItemAllFields;
//Set the metadata
string docTitle = string.Empty;
item["Title"] = "Dev";
item.Update();
uploadedFile.CheckIn(string.Empty, CheckinType.OverwriteCheckIn);
clientContext.ExecuteQuery();
You can get all the List Item Properties of the uploaded file as below and update all the metadata.
ListItem item = uploadFile.ListItemAllFields;
//Set the metadata
string docTitle = "Test Document";
item["Title"] = docTitle;
item.Update();
context.ExecuteQuery();
References:
- File Upload using CSOM
- Update Metadata
Below is the full code to upload the file and then update its property.
File uploadedFile = UploadFileSlicePerSlice(clientContext, "Documents", fileName, 3);
if(uploadedFile != null)
{
ListItem item = uploadedFile.ListItemAllFields;
//Set the metadata
string docTitle = string.Empty;
item["Title"] = "Dev";
item.Update();
clientContext.ExecuteQuery();
}
Note: Use UploadFileSlicePerSlice function mentioned in #1 reference to upload the file.