0

To help us move from legacy SharePoint to SharePoint Online, we have created an Azure App and written the code in C# to allow users to upload and download files using Active Directory authentication. So far, we have worked with libraries that don't have any required properties, but have come across one that has a required column. At present, the files upload to the library and are available to other users, but has a warning about missing required info:
Uploaded file metadata
Whilst the file is available to other authenticated users, it would be better if we could upload the file with this required property set.
This is the main block of code we use to upload a file to a site:

            var uploadProps = new DriveItemUploadableProperties
            {
                ODataType = null,
                AdditionalData = new Dictionary<string, object>
                {
                    {"@microsoft.graph.conflictBehavior", "replace"}
                }
            };

            var uploadSession = await GetAuthenticatedClient()
                .Drives[driveItem.ParentReference.DriveId]
                .Items[driveItem.Id]
                .CreateUploadSession(uploadProps)
                .Request()
                .PostAsync();

We then break the file into chunks to ensure it uploads correctly.
Is there an easy way to update the code to allow for the required field (titled 'WR Required?')?
Many thanks
Martin

2 Answers 2

1

After you uploading the file, you could use Update listItem method to set the column value, like this:

var fieldValueSet = new FieldValueSet
{
    AdditionalData = new Dictionary<string, object>()
    {
        {"Title", "test"},
        {"column1", "value"}
    }
};
await graphClient.Drives["{drive-id}"].Items["{driveitem-id}"].ListItem.Fields
    .Request()
    .UpdateAsync(fieldValueSet);
0

Can you please share the C# code, about how we can upload a file as a new Item? and after that Add this information in Share Point

2
  • It's not the answer, it's question. You can use Comment for asking this kind of question Feb 21, 2023 at 6:52
  • If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review Feb 21, 2023 at 7:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.