Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -573,24 +573,54 @@ 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())
{
var fieldValues = file.ListItemAllFields.FieldValues;

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)
{
Expand Down Expand Up @@ -732,6 +762,9 @@ public Model.Folder ExtractFolderSettings(Web web, List siteList, List<Dictionar
f => 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,
Expand All @@ -741,13 +774,35 @@ public Model.Folder ExtractFolderSettings(Web web, List siteList, List<Dictionar
w => 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())
{
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
if (spFolder.Properties.FieldValues.Any())
{
foreach (var propKey in spFolder.Properties.FieldValues.Keys.Where(k => !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() });
}
Expand All @@ -772,17 +827,33 @@ public Model.Folder ExtractFolderSettings(Web web, List siteList, List<Dictionar
{
if (spFolder.ListItemAllFields.ContentType.StringId.StartsWith(ct.StringId))
{
ctId = ct.StringId;
pnpFolder.ContentTypeID = ct.StringId;
break;
}
}

if (string.IsNullOrEmpty(ctId)
&& siteCollectionContext != null)
{
foreach (var ct in siteCollectionContext.Site.RootWeb.ContentTypes.OrderByDescending(c => c.StringId.Length))
{
if (spFolder.ListItemAllFields.ContentType.StringId.StartsWith(ct.StringId))
{
ctId = ct.StringId;
pnpFolder.ContentTypeID = ct.StringId;
break;
}
}
}
#endregion //**** get correct Content Type

var filteredFieldValues = fieldValues.ToList();
if (queryConfig != null && queryConfig.ViewFields != null && queryConfig.ViewFields.Count > 0)
{
filteredFieldValues = fieldValues.Where(f => queryConfig.ViewFields.Contains(f.Key)).ToList();
}

foreach (var fieldValue in filteredFieldValues)
{
if (fieldValue.Value != null && !string.IsNullOrEmpty(fieldValue.Value.ToString()))
Expand All @@ -795,7 +866,7 @@ public Model.Folder ExtractFolderSettings(Web web, List siteList, List<Dictionar
{
value = TokenizeValue(web, field.TypeAsString, fieldValue, fieldValuesAsText[field.InternalName]);
}

//We process moderation status, ideally this shoud be managed with a new attribute in Folder, but it requires a new schema version
if (fieldValue.Key.Equals("_ModerationStatus", StringComparison.InvariantCultureIgnoreCase))
{
Expand Down