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

Uploading a file to a site content type does not set the Content type field correctly (locks template file) #1520

Open
1 task done
metkhoo opened this issue Sep 1, 2024 · 2 comments
Labels
question Further information is requested

Comments

@metkhoo
Copy link

metkhoo commented Sep 1, 2024

Category

  • Bug

I can successfully create content types but the ContentType field is not correctly set when I use the content types to create documents in a document library.

Steps to reproduce

Context is a document library with an additional column "ContentType" added to the default view.

Then in code:

  • Create a site content type "CT1"
  • Upload a template files to the "Site Assets" library ("templatedoc1.docx")
  • Correctly assign the newly uploaded "templatedoc1.docx" to the content type "CT1"
  • Allocate the "CT1" content type to the Document library (ensuring content types is enabled on the document library)
  • Correctly see the content type "CT1" on the "New" menu of the document library
  • Create a second site content type "CT2"
  • Upload a template files to the "Site Assets" library ("templatedoc2.docx")
  • Correctly assign the newly uploaded "templatedoc2.docx" to the content type "CT2"
  • Allocate the "CT2" content type to the Document library
  • Correctly see the content type "CT2" on the "New" menu of the document library.
  • Remove the "Document" content type from the document library

If I create a content item using the "New > CT1" content type. The item is created with the content from "Templatedoc1.docx" When it gets saved it correctly sets the "ContentType" field to "CT1"
If i create an item using the "New > CT2" content type. The item is created with the correct content from "Templatedoc2.docx". When it gets saved though it gets set INCORRECTLY To "CT1"

Expected behavior

Creating a document from a content type with a template will correctly set the ContentType field. So in my example I expect the second document to have the "ContentType" field set to "CT2"

Environment details (development & target environment)

DELETE THIS LINE BEFORE SUBMITTING - Complete the following (if ignored you'll be prompted for it before we can address your issue... save the time and provide it in your initial submission).

SDK version: 1.14.0
OS: Windows 11
SDK used in: Console App
Framework: .NET 8.0
Browser(s): Edge Version 128.0.2739.42 (Official build) (64-bit)
Tooling: Visual Studio 2020 17.11

Additional context

The target site is a CLASSIC Team Site created from template STS#0
It I try to manually set the content type after creation I get the error message:

Error: The file is locked for shared use by [mylogin]

If I go to the document library > Library Settings > More Library settings
Select the document type then > Advanced settings
I see the correct path to the template document:
/sites/{mysite}/SiteAssets/TemplateDoc1.docx

If I use the "Upload the new document template" and select the file to upload manually and then create the items it all works correctly and the content type is allocated correctly.
If I do the same manual process for the content type at the SITE level it also works correctly and allocates the correct content type when an item is created.

I really want to know how I can programatically "Upload a new document template" in pnp.Core. (There are no examples)

Thanks for your contribution! Sharing is caring.

@metkhoo metkhoo changed the title Uploading a file to a site content type does not set the Content type field correctly Uploading a file to a site content type does not set the Content type field correctly (locks template file) Sep 2, 2024
@jansenbe jansenbe added the question Further information is requested label Sep 17, 2024
@jansenbe
Copy link
Contributor

@metkhoo : did you test this with CSOM as well? Wondering if you see the same behavior? So setting the DocumentTemplateUrl on the created contenttypes is not working?

@jansenbe
Copy link
Contributor

@metkhoo : you've any feedback here?

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

No branches or pull requests

2 participants