From 10bde7bae716aaae23f987ca2eacc07bec8eda31 Mon Sep 17 00:00:00 2001 From: gszdev <31336851+gszdev@users.noreply.github.com> Date: Thu, 30 Jul 2026 10:48:55 +0200 Subject: [PATCH 1/2] Fix for #1252 - Missing ContentTypeId when extracting list and library data from a sub site --- .../ObjectListInstanceDataRows.cs | 68 +++++++++++++++++-- 1 file changed, 61 insertions(+), 7 deletions(-) diff --git a/src/lib/PnP.Framework/Provisioning/ObjectHandlers/ObjectListInstanceDataRows.cs b/src/lib/PnP.Framework/Provisioning/ObjectHandlers/ObjectListInstanceDataRows.cs index 17ebfb331..aefc0e429 100644 --- a/src/lib/PnP.Framework/Provisioning/ObjectHandlers/ObjectListInstanceDataRows.cs +++ b/src/lib/PnP.Framework/Provisioning/ObjectHandlers/ObjectListInstanceDataRows.cs @@ -573,6 +573,16 @@ private void ExtractFileSettings(Web web, List siteList, Guid fileUniqueId, ref web.Context.ExecuteQueryRetry(); + ClientContext siteCollectionContext = null; + if (web.IsSubSite()) + { + siteCollectionContext = web.ParentWeb.Context as ClientContext; + siteCollectionContext.Site.RootWeb.EnsureProperties( + w => w.ServerRelativeUrl, + w => w.Url, + w => w.ContentTypes.Include(c => c.Id, c => c.Name, c => c.StringId)); + } + //export PnPFile FieldValues if (file.ListItemAllFields.FieldValues.Any()) { @@ -580,17 +590,37 @@ private void ExtractFileSettings(Web web, List siteList, Guid fileUniqueId, ref var fieldValuesAsText = file.ListItemAllFields.EnsureProperty(li => li.FieldValuesAsText).FieldValues; - #region //**** get correct Content Type - string ctId = string.Empty; - foreach (var ct in web.ContentTypes.OrderByDescending(c => c.StringId.Length)) + if (file.ListItemAllFields.ContentType.StringId != defaultContentTypeId) // skip if it is the default content type (don't run through loops if not needed) { - if (file.ListItemAllFields.ContentType.StringId.StartsWith(ct.StringId) && file.ListItemAllFields.ContentType.StringId != defaultContentTypeId) // skip if it is the default content type + #region //**** get correct Content Type + string ctId = string.Empty; + foreach (var ct in web.ContentTypes.OrderByDescending(c => c.StringId.Length)) { - pnpFile.Properties.Add("ContentTypeId", ct.StringId); - break; + if (file.ListItemAllFields.ContentType.StringId.StartsWith(ct.StringId)) + //&& file.ListItemAllFields.ContentType.StringId != defaultContentTypeId) // skip if it is the default content type + { + ctId = ct.StringId; + pnpFile.Properties.Add("ContentTypeId", ct.StringId); + break; + } + } + + if (string.IsNullOrEmpty(ctId) + && siteCollectionContext != null) + { + foreach (var ct in siteCollectionContext.Site.RootWeb.ContentTypes.OrderByDescending(c => c.StringId.Length)) + { + if (file.ListItemAllFields.ContentType.StringId.StartsWith(ct.StringId)) + //&& file.ListItemAllFields.ContentType.StringId != defaultContentTypeId) // skip if it is the default content type + { + ctId = ct.StringId; + pnpFile.Properties.Add("ContentTypeId", ct.StringId); + break; + } + } } + #endregion //**** get correct Content Type } - #endregion //**** get correct Content Type foreach (var fieldValue in fieldValues) { @@ -742,6 +772,17 @@ public Model.Folder ExtractFolderSettings(Web web, List siteList, List w.ContentTypes.Include(c => c.Id, c => c.Name, c => c.StringId)); web.Context.ExecuteQueryRetry(); + ClientContext siteCollectionContext = null; + if (web.IsSubSite()) + { + siteCollectionContext = web.ParentWeb.Context as ClientContext; + siteCollectionContext.Site.RootWeb.EnsureProperties( + w => w.ServerRelativeUrl, + w => w.Url, + w => w.ContentTypes.Include(c => c.Id, c => c.Name, c => c.StringId)); + } + + pnpFolder = new Model.Folder(spFolder.Name); //export PnPFolder Properties @@ -776,6 +817,19 @@ public Model.Folder ExtractFolderSettings(Web web, List siteList, List c.StringId.Length)) + { + if (spFolder.ListItemAllFields.ContentType.StringId.StartsWith(ct.StringId)) + { + pnpFolder.ContentTypeID = ct.StringId; + break; + } + } + } #endregion //**** get correct Content Type var filteredFieldValues = fieldValues.ToList(); From 55735f65659fc5604a4fbc560f5f07a4985003ca Mon Sep 17 00:00:00 2001 From: gszdev <31336851+gszdev@users.noreply.github.com> Date: Thu, 30 Jul 2026 16:10:11 +0200 Subject: [PATCH 2/2] Missing ContentTypeId when extracting list and library data from a sub site --- .../ObjectListInstanceDataRows.cs | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/lib/PnP.Framework/Provisioning/ObjectHandlers/ObjectListInstanceDataRows.cs b/src/lib/PnP.Framework/Provisioning/ObjectHandlers/ObjectListInstanceDataRows.cs index aefc0e429..07ff99290 100644 --- a/src/lib/PnP.Framework/Provisioning/ObjectHandlers/ObjectListInstanceDataRows.cs +++ b/src/lib/PnP.Framework/Provisioning/ObjectHandlers/ObjectListInstanceDataRows.cs @@ -762,6 +762,9 @@ public Model.Folder ExtractFolderSettings(Web web, List siteList, List f.ListItemAllFields.HasUniqueRoleAssignments, f => f.ListItemAllFields.ParentList, f => f.ListItemAllFields.ContentType.StringId); + + web.Context.ExecuteQueryRetry(); + /* web.Context.Load(web, w => w.AssociatedOwnerGroup, w => w.AssociatedMemberGroup, @@ -771,6 +774,16 @@ public Model.Folder ExtractFolderSettings(Web web, List siteList, List w.RoleDefinitions.Include(r => r.RoleTypeKind, r => r.Name), w => w.ContentTypes.Include(c => c.Id, c => c.Name, c => c.StringId)); web.Context.ExecuteQueryRetry(); + */ + + web.EnsureProperties( + w => w.AssociatedOwnerGroup, + w => w.AssociatedMemberGroup, + w => w.AssociatedVisitorGroup, + w => w.Title, + w => w.Url, + w => w.RoleDefinitions.Include(r => r.RoleTypeKind, r => r.Name), + w => w.ContentTypes.Include(c => c.Id, c => c.Name, c => c.StringId)); ClientContext siteCollectionContext = null; if (web.IsSubSite()) @@ -788,7 +801,8 @@ public Model.Folder ExtractFolderSettings(Web web, List siteList, List !k.StartsWith("vti_") && !k.StartsWith("docset_"))) + var entries = spFolder.Properties.FieldValues.Keys.Where(k => !k.StartsWith("vti_") && !k.StartsWith("docset_")); + foreach (var propKey in entries) { pnpFolder.PropertyBagEntries.Add(new PropertyBagEntry() { Key = propKey, Value = spFolder.Properties.FieldValues[propKey].ToString() }); } @@ -813,6 +827,7 @@ public Model.Folder ExtractFolderSettings(Web web, List siteList, List queryConfig.ViewFields.Contains(f.Key)).ToList(); } + foreach (var fieldValue in filteredFieldValues) { if (fieldValue.Value != null && !string.IsNullOrEmpty(fieldValue.Value.ToString())) @@ -849,7 +866,7 @@ public Model.Folder ExtractFolderSettings(Web web, List siteList, List