Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot update File's term (managed metadata) property if the file is a .docx, .xlsx, ect. #1503

Open
1 task done
IllumiC opened this issue Aug 7, 2024 · 4 comments
Open
1 task done

Comments

@IllumiC
Copy link

IllumiC commented Aug 7, 2024

Category

  • Bug

Describe the bug

I use the following code to obtain the file properties and load the relevant data to edit its properties.

SharePoint.IFile file;
await using (Stream fileStream = await fileClient.OpenReadAsync())
{
    file = await folder.Files.AddAsync(fileClient.Name, fileStream, true);
}
await file.LoadAsync(f => f.ListItemAllFields.QueryProperties(
    listItem => listItem.All,
    listItem => listItem.ParentList.QueryProperties(
        list => list.Title,
        list => list.Fields.QueryProperties(
            field => field.InternalName,
            field => field.FieldTypeKind,
            field => field.TypeAsString,
            field => field.Title
        )
    )
));

I use the following code to edit the TermFieldName property.

file.ListItemAllFields["TermFieldName"] = "4f3f1ac3-f9b4-4b50-979a-82e97108390f" // single term (managed metadata)
file.ListItemAllFields["Subject"] = file.Name // single line text
await file.ListItemAllFields.UpdateOverwriteVersionAsync();

I have tested this on the file extensions pdf, jpg, txt, odt, rtf, doc, docx and xlsx.
All extensions other than docx and xlsx have their files update both the TermFieldName and Subject. Docx and xlsx updates the Subject but not the TermFieldName.

Steps to reproduce

Use ListItemAllFields to update a term (managed metadata) alongside any other fields. When attempting on a docx or xlsx file, the term field will not be populated, but other fields are in the same UpdateOverwriteVersionAsync() call. file.ListItemAllFields.Values shows the term field guid.

Expected behavior

The TermFieldName will be populated.

Environment details (development & target environment)

  • SDK version: 1.12.0 / 1.13.0
  • OS: Windows 10
  • SDK used in: Azure WebJob (manually triggered)
  • Framework: .NET Core 6.0
  • Browser(s): Console
  • Tooling: Visual Studio 2022
  • Additional details: The more context you can provide, the easier it is (and therefore quicker) to help.

Additional context

No error is displayed. All other fields are updated, however the term fields are ignored.
Both fields are required. There are other optional fields and required fields which are not always populated.
The file is newly created using PnP Core SDK prior to attempting to edit it.

@IllumiC
Copy link
Author

IllumiC commented Aug 7, 2024

The issue occurs using any of SystemUpdateAsync() and UpdateOverwriteVersionAsync().
Using UpdateAsync() causes the following error on ALL files (not just docx / xlsx):
SharePointRestServiceException: There was an exception while writing field TermFieldName. Verify you're using the correct InternalName value for the field you want to write to.

@IllumiC
Copy link
Author

IllumiC commented Aug 7, 2024

Out of curiosity to make sure I'm not going insane.. I am changing the extension of the file via code to .tmp. The .tmp file allows the term to be set.

@IllumiC
Copy link
Author

IllumiC commented Aug 8, 2024

I ran the following code after to see what the client sees..

                    IFile editedFile = pnpRepositoryContext.Web.GetFileByServerRelativeUrl(addedFile.ServerRelativeUrl);
                    await editedFile.LoadAsync(f => f.ListItemAllFields.QueryProperties(
                        listItem => listItem.All,
                        listItem => listItem.ParentList.QueryProperties(
                            list => list.Title,
                            list => list.Fields.QueryProperties(
                                field => field.InternalName,
                                field => field.FieldTypeKind,
                                field => field.TypeAsString,
                                field => field.Title
                            )
                        )
                    ));

                    await file.LoadAsync(f => f.ListItemAllFields.QueryProperties(
                        listItem => listItem.All,
                        listItem => listItem.ParentList.QueryProperties(
                            list => list.Title,
                            list => list.Fields.QueryProperties(
                                field => field.InternalName,
                                field => field.FieldTypeKind,
                                field => field.TypeAsString,
                                field => field.Title
                            )
                        )
                    ));

editedFile.ListItemAllFields Values contains a null entry for the term fields, while file.ListItemAllFields Values related to the terms remain populated.

@jansenbe
Copy link
Contributor

@IllumiC : is this currently still an issue? Feels much like a temporary system glitch...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants