本文整理汇总了C#中OfficeDevPnP.Core.Framework.Provisioning.ObjectHandlers.TokenParser.AddToken方法的典型用法代码示例。如果您正苦于以下问题:C# TokenParser.AddToken方法的具体用法?C# TokenParser.AddToken怎么用?C# TokenParser.AddToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OfficeDevPnP.Core.Framework.Provisioning.ObjectHandlers.TokenParser
的用法示例。
在下文中一共展示了TokenParser.AddToken方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddExtendedTokens
public TokenParser AddExtendedTokens(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation)
{
using (var scope = new PnPMonitoredScope(this.Name))
{
var context = web.Context as ClientContext;
foreach (var provider in template.Providers)
{
if (provider.Enabled)
{
try
{
if (!string.IsNullOrEmpty(provider.Configuration))
{
provider.Configuration = parser.ParseString(provider.Configuration);
}
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ExtensibilityProviders_Calling_tokenprovider_extensibility_callout__0_, provider.Assembly);
var _providedTokens = _extManager.ExecuteTokenProviderCallOut(context, provider, template);
if (_providedTokens != null)
{
foreach (var token in _providedTokens)
{
parser.AddToken(token);
}
}
}
catch (Exception ex)
{
scope.LogError(CoreResources.Provisioning_ObjectHandlers_ExtensibilityProviders_tokenprovider_callout_failed___0_____1_, ex.Message, ex.StackTrace);
throw;
}
}
}
return parser;
}
}
示例2: ProvisionObjects
public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation)
{
using (var scope = new PnPMonitoredScope(this.Name))
{
var context = web.Context as ClientContext;
web.EnsureProperties(w => w.ServerRelativeUrl, w => w.RootFolder.WelcomePage);
foreach (var page in template.Pages)
{
var url = parser.ParseString(page.Url);
if (!url.ToLower().StartsWith(web.ServerRelativeUrl.ToLower()))
{
url = UrlUtility.Combine(web.ServerRelativeUrl, url);
}
var exists = true;
Microsoft.SharePoint.Client.File file = null;
try
{
file = web.GetFileByServerRelativeUrl(url);
web.Context.Load(file);
web.Context.ExecuteQuery();
}
catch (ServerException ex)
{
if (ex.ServerErrorTypeName == "System.IO.FileNotFoundException")
{
exists = false;
}
}
if (exists)
{
if (page.Overwrite)
{
try
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Pages_Overwriting_existing_page__0_, url);
if (page.WelcomePage && url.Contains(web.RootFolder.WelcomePage))
web.SetHomePage(string.Empty);
file.DeleteObject();
web.Context.ExecuteQueryRetry();
web.AddWikiPageByUrl(url);
if (page.Layout == WikiPageLayout.Custom)
{
web.AddLayoutToWikiPage(WikiPageLayout.OneColumn, url);
}
else {
web.AddLayoutToWikiPage(page.Layout, url);
}
}
catch (Exception ex)
{
scope.LogError(CoreResources.Provisioning_ObjectHandlers_Pages_Overwriting_existing_page__0__failed___1_____2_, url, ex.Message, ex.StackTrace);
}
}
}
else
{
try
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Pages_Creating_new_page__0_, url);
web.AddWikiPageByUrl(url);
web.AddLayoutToWikiPage(page.Layout, url);
}
catch (Exception ex)
{
scope.LogError(CoreResources.Provisioning_ObjectHandlers_Pages_Creating_new_page__0__failed___1_____2_, url, ex.Message, ex.StackTrace);
}
}
if (page.WelcomePage)
{
web.RootFolder.EnsureProperty(p => p.ServerRelativeUrl);
var rootFolderRelativeUrl = url.Substring(web.RootFolder.ServerRelativeUrl.Length);
web.SetHomePage(rootFolderRelativeUrl);
}
if (page.WebParts != null & page.WebParts.Any())
{
var existingWebParts = web.GetWebParts(url);
foreach (var webpart in page.WebParts)
{
if (existingWebParts.FirstOrDefault(w => w.WebPart.Title == webpart.Title) == null)
{
WebPartEntity wpEntity = new WebPartEntity();
wpEntity.WebPartTitle = webpart.Title;
wpEntity.WebPartXml = parser.ParseString(webpart.Contents.Trim(new[] { '\n', ' ' }));
web.AddWebPartToWikiPage(url, wpEntity, (int)webpart.Row, (int)webpart.Column, false);
}
}
var allWebParts = web.GetWebParts(url);
foreach (var webpart in allWebParts)
{
parser.AddToken(new WebPartIdToken(web, webpart.WebPart.Title, webpart.Id));
//.........这里部分代码省略.........
示例3: ProvisionObjects
public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation)
{
using (var scope = new PnPMonitoredScope(this.Name))
{
if (template.Lists.Any())
{
var rootWeb = (web.Context as ClientContext).Site.RootWeb;
web.EnsureProperties(w => w.ServerRelativeUrl);
web.Context.Load(web.Lists, lc => lc.IncludeWithDefaultProperties(l => l.RootFolder.ServerRelativeUrl));
web.Context.ExecuteQueryRetry();
var existingLists = web.Lists.AsEnumerable().Select(existingList => existingList.RootFolder.ServerRelativeUrl).ToList();
var serverRelativeUrl = web.ServerRelativeUrl;
var processedLists = new List<ListInfo>();
#region Lists
foreach (var templateList in template.Lists)
{
// Check for the presence of the references content types and throw an exception if not present or in template
if (templateList.ContentTypesEnabled)
{
var existingCts = web.Context.LoadQuery(web.AvailableContentTypes);
web.Context.ExecuteQueryRetry();
foreach (var ct in templateList.ContentTypeBindings)
{
var found = template.ContentTypes.Any(t => t.Id.ToUpperInvariant() == ct.ContentTypeId.ToUpperInvariant());
if (found == false)
{
found = existingCts.Any(t => t.StringId.ToUpperInvariant() == ct.ContentTypeId.ToUpperInvariant());
}
if (!found)
{
scope.LogError("Referenced content type {0} not available in site or in template", ct.ContentTypeId);
throw new Exception(string.Format("Referenced content type {0} not available in site or in template", ct.ContentTypeId));
}
}
}
var index = existingLists.FindIndex(x => x.Equals(UrlUtility.Combine(serverRelativeUrl, templateList.Url), StringComparison.OrdinalIgnoreCase));
if (index == -1)
{
try
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ListInstances_Creating_list__0_, templateList.Title);
var returnTuple = CreateList(web, templateList, parser, scope);
var createdList = returnTuple.Item1;
parser = returnTuple.Item2;
processedLists.Add(new ListInfo { SiteList = createdList, TemplateList = templateList });
parser.AddToken(new ListIdToken(web, templateList.Title, createdList.Id));
parser.AddToken(new ListUrlToken(web, templateList.Title, createdList.RootFolder.ServerRelativeUrl.Substring(web.ServerRelativeUrl.Length + 1)));
}
catch (Exception ex)
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ListInstances_Creating_list__0__failed___1_____2_, templateList.Title, ex.Message, ex.StackTrace);
throw;
}
}
else
{
try
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ListInstances_Updating_list__0_, templateList.Title);
var existingList = web.Lists[index];
var returnTuple = UpdateList(web, existingList, templateList, parser, scope);
var updatedList = returnTuple.Item1;
parser = returnTuple.Item2;
if (updatedList != null)
{
processedLists.Add(new ListInfo { SiteList = updatedList, TemplateList = templateList });
}
}
catch (Exception ex)
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ListInstances_Updating_list__0__failed___1_____2_, templateList.Title, ex.Message, ex.StackTrace);
throw;
}
}
}
#endregion
#region FieldRefs
foreach (var listInfo in processedLists)
{
if (listInfo.TemplateList.FieldRefs.Any())
{
foreach (var fieldRef in listInfo.TemplateList.FieldRefs)
{
var field = rootWeb.GetFieldById<Field>(fieldRef.Id);
if (field != null)
{
if (!listInfo.SiteList.FieldExistsById(fieldRef.Id))
{
//.........这里部分代码省略.........
示例4: ProvisionObjects
public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation)
{
using (var scope = new PnPMonitoredScope(this.Name))
{
// Changed by Paolo Pialorsi to embrace the new sub-site attributes for break role inheritance and copy role assignments
// if this is a sub site then we're not provisioning security as by default security is inherited from the root site
//if (web.IsSubSite() && !template.Security.BreakRoleInheritance)
//{
// scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_SiteSecurity_Context_web_is_subweb__skipping_site_security_provisioning);
// return parser;
//}
if (web.IsSubSite() && template.Security.BreakRoleInheritance)
{
web.BreakRoleInheritance(template.Security.CopyRoleAssignments, template.Security.ClearSubscopes);
web.Update();
web.Context.ExecuteQueryRetry();
}
var siteSecurity = template.Security;
var ownerGroup = web.AssociatedOwnerGroup;
var memberGroup = web.AssociatedMemberGroup;
var visitorGroup = web.AssociatedVisitorGroup;
web.Context.Load(ownerGroup, o => o.Title, o => o.Users);
web.Context.Load(memberGroup, o => o.Title, o => o.Users);
web.Context.Load(visitorGroup, o => o.Title, o => o.Users);
web.Context.ExecuteQueryRetry();
if (!ownerGroup.ServerObjectIsNull.Value)
{
AddUserToGroup(web, ownerGroup, siteSecurity.AdditionalOwners, scope, parser);
}
if (!memberGroup.ServerObjectIsNull.Value)
{
AddUserToGroup(web, memberGroup, siteSecurity.AdditionalMembers, scope, parser);
}
if (!visitorGroup.ServerObjectIsNull.Value)
{
AddUserToGroup(web, visitorGroup, siteSecurity.AdditionalVisitors, scope, parser);
}
foreach (var siteGroup in siteSecurity.SiteGroups)
{
Group group;
var allGroups = web.Context.LoadQuery(web.SiteGroups.Include(gr => gr.LoginName));
web.Context.ExecuteQueryRetry();
string parsedGroupTitle = parser.ParseString(siteGroup.Title);
string parsedGroupOwner = parser.ParseString(siteGroup.Owner);
string parsedGroupDescription = parser.ParseString(siteGroup.Description);
if (!web.GroupExists(parsedGroupTitle))
{
scope.LogDebug("Creating group {0}", parsedGroupTitle);
group = web.AddGroup(
parsedGroupTitle,
parsedGroupDescription,
parsedGroupTitle == parsedGroupOwner);
group.AllowMembersEditMembership = siteGroup.AllowMembersEditMembership;
group.AllowRequestToJoinLeave = siteGroup.AllowRequestToJoinLeave;
group.AutoAcceptRequestToJoinLeave = siteGroup.AutoAcceptRequestToJoinLeave;
if (parsedGroupTitle != parsedGroupOwner)
{
Principal ownerPrincipal = allGroups.FirstOrDefault(gr => gr.LoginName == parsedGroupOwner);
if (ownerPrincipal == null)
{
ownerPrincipal = web.EnsureUser(parsedGroupOwner);
}
group.Owner = ownerPrincipal;
}
group.Update();
web.Context.Load(group, g => g.Id, g => g.Title);
web.Context.ExecuteQueryRetry();
parser.AddToken(new GroupIdToken(web, group.Title, group.Id));
}
else
{
group = web.SiteGroups.GetByName(parsedGroupTitle);
web.Context.Load(group,
g => g.Title,
g => g.Description,
g => g.AllowMembersEditMembership,
g => g.AllowRequestToJoinLeave,
g => g.AutoAcceptRequestToJoinLeave,
g => g.Owner.LoginName);
web.Context.ExecuteQueryRetry();
var isDirty = false;
if (!String.IsNullOrEmpty(group.Description) && group.Description != parsedGroupDescription)
{
group.Description = parsedGroupDescription;
isDirty = true;
}
if (group.AllowMembersEditMembership != siteGroup.AllowMembersEditMembership)
{
//.........这里部分代码省略.........
示例5: UpdateContentType
private static void UpdateContentType(Web web, Microsoft.SharePoint.Client.ContentType existingContentType, ContentType templateContentType, TokenParser parser, PnPMonitoredScope scope)
{
var isDirty = false;
if (existingContentType.Hidden != templateContentType.Hidden)
{
scope.LogPropertyUpdate("Hidden");
existingContentType.Hidden = templateContentType.Hidden;
isDirty = true;
}
if (existingContentType.ReadOnly != templateContentType.ReadOnly)
{
scope.LogPropertyUpdate("ReadOnly");
existingContentType.ReadOnly = templateContentType.ReadOnly;
isDirty = true;
}
if (existingContentType.Sealed != templateContentType.Sealed)
{
scope.LogPropertyUpdate("Sealed");
existingContentType.Sealed = templateContentType.Sealed;
isDirty = true;
}
if (templateContentType.Description != null && existingContentType.Description != parser.ParseString(templateContentType.Description))
{
scope.LogPropertyUpdate("Description");
existingContentType.Description = parser.ParseString(templateContentType.Description);
isDirty = true;
}
if (templateContentType.DocumentTemplate != null && existingContentType.DocumentTemplate != parser.ParseString(templateContentType.DocumentTemplate))
{
scope.LogPropertyUpdate("DocumentTemplate");
existingContentType.DocumentTemplate = parser.ParseString(templateContentType.DocumentTemplate);
isDirty = true;
}
if (existingContentType.Name != parser.ParseString(templateContentType.Name))
{
scope.LogPropertyUpdate("Name");
existingContentType.Name = parser.ParseString(templateContentType.Name);
isDirty = true;
// CT is being renamed, add an extra token to the tokenparser
parser.AddToken(new ContentTypeIdToken(web, existingContentType.Name, existingContentType.StringId));
}
if (templateContentType.Group != null && existingContentType.Group != parser.ParseString(templateContentType.Group))
{
scope.LogPropertyUpdate("Group");
existingContentType.Group = parser.ParseString(templateContentType.Group);
isDirty = true;
}
if (templateContentType.DisplayFormUrl != null && existingContentType.DisplayFormUrl != parser.ParseString(templateContentType.DisplayFormUrl))
{
scope.LogPropertyUpdate("DisplayFormUrl");
existingContentType.DisplayFormUrl = parser.ParseString(templateContentType.DisplayFormUrl);
isDirty = true;
}
if (templateContentType.EditFormUrl != null && existingContentType.EditFormUrl != parser.ParseString(templateContentType.EditFormUrl))
{
scope.LogPropertyUpdate("EditFormUrl");
existingContentType.EditFormUrl = parser.ParseString(templateContentType.EditFormUrl);
isDirty = true;
}
if (templateContentType.NewFormUrl != null && existingContentType.NewFormUrl != parser.ParseString(templateContentType.NewFormUrl))
{
scope.LogPropertyUpdate("NewFormUrl");
existingContentType.NewFormUrl = parser.ParseString(templateContentType.NewFormUrl);
isDirty = true;
}
#if !CLIENTSDKV15
if (templateContentType.Name.ContainsResourceToken())
{
existingContentType.NameResource.SetUserResourceValue(templateContentType.Name, parser);
isDirty = true;
}
if (templateContentType.Description.ContainsResourceToken())
{
existingContentType.DescriptionResource.SetUserResourceValue(templateContentType.Description, parser);
isDirty = true;
}
#endif
if (isDirty)
{
existingContentType.Update(true);
web.Context.ExecuteQueryRetry();
}
// Delta handling
existingContentType.EnsureProperty(c => c.FieldLinks);
List<Guid> targetIds = existingContentType.FieldLinks.AsEnumerable().Select(c1 => c1.Id).ToList();
List<Guid> sourceIds = templateContentType.FieldRefs.Select(c1 => c1.Id).ToList();
var fieldsNotPresentInTarget = sourceIds.Except(targetIds).ToArray();
if (fieldsNotPresentInTarget.Any())
{
foreach (var fieldId in fieldsNotPresentInTarget)
{
var fieldRef = templateContentType.FieldRefs.Find(fr => fr.Id == fieldId);
var field = web.Fields.GetById(fieldId);
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ContentTypes_Adding_field__0__to_content_type, fieldId);
web.AddFieldToContentType(existingContentType, field, fieldRef.Required, fieldRef.Hidden);
}
}
//.........这里部分代码省略.........
示例6: UpdateList
private Tuple<List, TokenParser> UpdateList(Web web, List existingList, ListInstance templateList, TokenParser parser, PnPMonitoredScope scope)
{
web.Context.Load(existingList,
l => l.Title,
l => l.Description,
l => l.OnQuickLaunch,
l => l.Hidden,
l => l.ContentTypesEnabled,
l => l.EnableAttachments,
l => l.EnableFolderCreation,
l => l.EnableMinorVersions,
l => l.DraftVersionVisibility,
l => l.Views,
l => l.RootFolder
#if !CLIENTSDKV15
, l => l.MajorWithMinorVersionsLimit
#endif
);
web.Context.ExecuteQueryRetry();
if (existingList.BaseTemplate == templateList.TemplateType)
{
var isDirty = false;
if (parser.ParseString(templateList.Title) != existingList.Title)
{
var oldTitle = existingList.Title;
existingList.Title = parser.ParseString(templateList.Title);
if (!oldTitle.Equals(existingList.Title, StringComparison.OrdinalIgnoreCase))
{
parser.AddToken(new ListIdToken(web, existingList.Title, existingList.Id));
parser.AddToken(new ListUrlToken(web, existingList.Title, existingList.RootFolder.ServerRelativeUrl.Substring(web.ServerRelativeUrl.Length + 1)));
}
isDirty = true;
}
if (!string.IsNullOrEmpty(templateList.DocumentTemplate))
{
if (existingList.DocumentTemplateUrl != parser.ParseString(templateList.DocumentTemplate))
{
existingList.DocumentTemplateUrl = parser.ParseString(templateList.DocumentTemplate);
isDirty = true;
}
}
if (!string.IsNullOrEmpty(templateList.Description) && templateList.Description != existingList.Description)
{
existingList.Description = templateList.Description;
isDirty = true;
}
if (templateList.Hidden != existingList.Hidden)
{
existingList.Hidden = templateList.Hidden;
isDirty = true;
}
if (templateList.OnQuickLaunch != existingList.OnQuickLaunch)
{
existingList.OnQuickLaunch = templateList.OnQuickLaunch;
isDirty = true;
}
if (existingList.BaseTemplate != (int)ListTemplateType.Survey &&
templateList.ContentTypesEnabled != existingList.ContentTypesEnabled)
{
existingList.ContentTypesEnabled = templateList.ContentTypesEnabled;
isDirty = true;
}
if (existingList.BaseTemplate != (int)ListTemplateType.Survey && existingList.BaseTemplate != (int)ListTemplateType.DocumentLibrary)
{
// https://msdn.microsoft.com/EN-US/library/microsoft.sharepoint.splist.enableattachments.aspx
// The EnableAttachments property does not apply to any list that has a base type of Survey or DocumentLibrary.
// If you set this property to true for either type of list, it throws an SPException.
if (templateList.EnableAttachments != existingList.EnableAttachments)
{
existingList.EnableAttachments = templateList.EnableAttachments;
isDirty = true;
}
}
if (existingList.BaseTemplate != (int)ListTemplateType.DiscussionBoard)
{
if (templateList.EnableFolderCreation != existingList.EnableFolderCreation)
{
existingList.EnableFolderCreation = templateList.EnableFolderCreation;
isDirty = true;
}
}
if (templateList.EnableVersioning)
{
if (existingList.EnableVersioning != templateList.EnableVersioning)
{
existingList.EnableVersioning = templateList.EnableVersioning;
isDirty = true;
}
#if !CLIENTSDKV15
if (existingList.IsObjectPropertyInstantiated("MajorVersionLimit") && existingList.MajorVersionLimit != templateList.MaxVersionLimit)
{
existingList.MajorVersionLimit = templateList.MaxVersionLimit;
isDirty = true;
}
#endif
if (existingList.BaseType == BaseType.DocumentLibrary)
{
// Only supported on Document Libraries
if (templateList.EnableMinorVersions != existingList.EnableMinorVersions)
//.........这里部分代码省略.........
示例7: CreateContentType
private static Microsoft.SharePoint.Client.ContentType CreateContentType(Web web, ContentType templateContentType, TokenParser parser, FileConnectorBase connector, PnPMonitoredScope scope,
List<Microsoft.SharePoint.Client.ContentType> existingCTs = null, List<Microsoft.SharePoint.Client.Field> existingFields = null, bool isNoScriptSite = false)
{
var name = parser.ParseString(templateContentType.Name);
var description = parser.ParseString(templateContentType.Description);
var id = parser.ParseString(templateContentType.Id);
var group = parser.ParseString(templateContentType.Group);
var createdCT = web.CreateContentType(name, description, id, group);
foreach (var fieldRef in templateContentType.FieldRefs)
{
Microsoft.SharePoint.Client.Field field = null;
try
{
// Try to get the field by ID
field = web.Fields.GetById(fieldRef.Id);
}
catch (ArgumentException)
{
// In case of failure, if we have the name
if (!String.IsNullOrEmpty(fieldRef.Name))
{
// Let's try with that one
field = web.Fields.GetByInternalNameOrTitle(fieldRef.Name);
}
}
// Add it to the target content type
// Notice that this code will fail if the field does not exist
web.AddFieldToContentType(createdCT, field, fieldRef.Required, fieldRef.Hidden);
}
// Add new CTs
parser.AddToken(new ContentTypeIdToken(web, name, id));
#if !ONPREMISES
// Set resources
if (templateContentType.Name.ContainsResourceToken())
{
createdCT.NameResource.SetUserResourceValue(templateContentType.Name, parser);
}
if (templateContentType.Description.ContainsResourceToken())
{
createdCT.DescriptionResource.SetUserResourceValue(templateContentType.Description, parser);
}
#endif
//Reorder the elements so that the new created Content Type has the same order as defined in the
//template. The order can be different if the new Content Type inherits from another Content Type.
//In this case the new Content Type has all field of the original Content Type and missing fields
//will be added at the end. To fix this issue we ordering the fields once more.
createdCT.FieldLinks.Reorder(templateContentType.FieldRefs.Select(fld => parser.ParseString(fld.Name)).ToArray());
createdCT.ReadOnly = templateContentType.ReadOnly;
createdCT.Hidden = templateContentType.Hidden;
createdCT.Sealed = templateContentType.Sealed;
if (templateContentType.DocumentSetTemplate == null)
{
// Only apply a document template when the contenttype is not a document set
if (!string.IsNullOrEmpty(parser.ParseString(templateContentType.DocumentTemplate)))
{
createdCT.DocumentTemplate = parser.ParseString(templateContentType.DocumentTemplate);
}
}
// Skipping updates of forms as we can't upload forms to noscript sites
if (!isNoScriptSite)
{
if (!String.IsNullOrEmpty(parser.ParseString(templateContentType.NewFormUrl)))
{
createdCT.NewFormUrl = parser.ParseString(templateContentType.NewFormUrl);
}
if (!String.IsNullOrEmpty(parser.ParseString(templateContentType.EditFormUrl)))
{
createdCT.EditFormUrl = parser.ParseString(templateContentType.EditFormUrl);
}
if (!String.IsNullOrEmpty(parser.ParseString(templateContentType.DisplayFormUrl)))
{
createdCT.DisplayFormUrl = parser.ParseString(templateContentType.DisplayFormUrl);
}
}
else
{
if (!String.IsNullOrEmpty(parser.ParseString(templateContentType.DisplayFormUrl)) ||
!String.IsNullOrEmpty(parser.ParseString(templateContentType.EditFormUrl)) ||
!String.IsNullOrEmpty(parser.ParseString(templateContentType.NewFormUrl)))
{
// log message
scope.LogWarning(CoreResources.Provisioning_ObjectHandlers_ContentTypes_SkipCustomFormUrls, name);
}
}
createdCT.Update(true);
web.Context.ExecuteQueryRetry();
// If the CT is a DocumentSet
if (templateContentType.DocumentSetTemplate != null)
{
// Retrieve a reference to the DocumentSet Content Type
//.........这里部分代码省略.........
示例8: ProvisionObjects
public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation)
{
using (var scope = new PnPMonitoredScope(this.Name))
{
if (template.Lists.Any())
{
var rootWeb = (web.Context as ClientContext).Site.RootWeb;
rootWeb.Context.Load(rootWeb.Fields);
web.Context.Load(web, w => w.ServerRelativeUrl);
web.Context.Load(web.Lists, lc => lc.IncludeWithDefaultProperties(
l => l.RootFolder.ServerRelativeUrl,
l => l.Title,
l => l.ParentWebUrl,
l => l.Id,
l => l.Description,
l => l.OnQuickLaunch,
l => l.Hidden,
l => l.Fields.IncludeWithDefaultProperties(
f => f.SchemaXml
),
l => l.ContentTypesEnabled,
l => l.ContentTypes.IncludeWithDefaultProperties(
ct => ct.Id,
ct => ct.StringId,
ct => ct.Name),
l => l.EnableAttachments,
l => l.EnableFolderCreation,
l => l.EnableMinorVersions,
l => l.DraftVersionVisibility,
l => l.Views
#if !CLIENTSDKV15
, l => l.MajorWithMinorVersionsLimit
#endif
));
var existingCts = web.AvailableContentTypes;
web.Context.Load(existingCts,
cts => cts.IncludeWithDefaultProperties(
ct => ct.Id,
ct => ct.StringId,
ct => ct.Name));
web.Context.ExecuteQueryRetry();
var existingLists = web.Lists.AsEnumerable().Select(existingList => existingList.RootFolder.ServerRelativeUrl).ToList();
var serverRelativeUrl = web.ServerRelativeUrl;
var processedLists = new List<ListInfo>();
#region Lists
foreach (var templateList in template.Lists)
{
// Check for the presence of the references content types and throw an exception if not present or in template
if (templateList.ContentTypesEnabled)
{
foreach (var ct in templateList.ContentTypeBindings)
{
var found = template.ContentTypes.Any(t => t.Id.ToUpperInvariant() == ct.ContentTypeId.ToUpperInvariant());
if (found == false)
{
found = existingCts.Any(t => t.StringId.ToUpperInvariant() == ct.ContentTypeId.ToUpperInvariant());
}
if (!found)
{
scope.LogError("Referenced content type {0} not available in site or in template", ct.ContentTypeId);
throw new Exception(string.Format("Referenced content type {0} not available in site or in template", ct.ContentTypeId));
}
}
}
var index = existingLists.FindIndex(x => x.Equals(UrlUtility.Combine(serverRelativeUrl, templateList.Url), StringComparison.OrdinalIgnoreCase));
if (index == -1)
{
try
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ListInstances_Creating_list__0_, templateList.Title);
var returnTuple = CreateList(web, templateList, parser, scope);
var createdList = returnTuple.Item1;
parser = returnTuple.Item2;
processedLists.Add(new ListInfo { SiteList = createdList, TemplateList = templateList });
parser.AddToken(new ListIdToken(web, templateList.Title, createdList.Id));
parser.AddToken(new ListUrlToken(web, templateList.Title, createdList.RootFolder.ServerRelativeUrl.Substring(web.ServerRelativeUrl.Length + (web.ServerRelativeUrl == "/" ? 0 : 1))));
}
catch (Exception ex)
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ListInstances_Creating_list__0__failed___1_____2_, templateList.Title, ex.Message, ex.StackTrace);
//throw;
}
}
else
{
try
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ListInstances_Updating_list__0_, templateList.Title);
var existingList = web.Lists[index];
var returnTuple = UpdateList(web, existingList, templateList, parser, scope);
var updatedList = returnTuple.Item1;
//.........这里部分代码省略.........
示例9: RegexSpecialCharactersTests
public void RegexSpecialCharactersTests()
{
using (var ctx = TestCommon.CreateClientContext())
{
ctx.Load(ctx.Web, w => w.Id, w => w.ServerRelativeUrl, w => w.Title, w => w.AssociatedOwnerGroup.Title, w => w.AssociatedMemberGroup.Title, w => w.AssociatedVisitorGroup.Title);
ctx.Load(ctx.Site, s => s.ServerRelativeUrl);
ctx.ExecuteQueryRetry();
var currentUser = ctx.Web.EnsureProperty(w => w.CurrentUser);
ProvisioningTemplate template = new ProvisioningTemplate();
template.Parameters.Add("test(T)", "test");
var parser = new TokenParser(ctx.Web, template);
var web = ctx.Web;
var contentTypeName = "Test CT (TC) [TC].$";
var contentTypeId = "0x010801006439AECCDEAE4db2A422A3A04C79CC83";
var listGuid = Guid.NewGuid();
var listTitle = @"List (\,*+?|{[()^$.#";
var listUrl = "Lists/TestList";
var webPartTitle = @"Webpart (\*+?|{[()^$.#";
var webPartId = Guid.NewGuid();
var termSetName = @"Test TermSet (\*+?{[()^$.#";
var termGroupName = @"Group Name (\*+?{[()^$.#";
var termStoreName = @"Test TermStore (\*+?{[()^$.#";
var termSetId = Guid.NewGuid();
var termStoreId = Guid.NewGuid();
// Use fake data
parser.AddToken(new ContentTypeIdToken(web, contentTypeName, contentTypeId));
parser.AddToken(new ListIdToken(web, listTitle, listGuid));
parser.AddToken(new ListUrlToken(web, listTitle, listUrl));
parser.AddToken(new WebPartIdToken(web, webPartTitle, webPartId));
parser.AddToken(new TermSetIdToken(web, termGroupName, termSetName, termSetId));
parser.AddToken(new TermStoreIdToken(web, termStoreName, termStoreId));
var resolvedContentTypeId = parser.ParseString($"{{contenttypeid:{contentTypeName}}}");
var resolvedListId = parser.ParseString($"{{listid:{listTitle}}}");
var resolvedListUrl = parser.ParseString($"{{listurl:{listTitle}}}");
var parameterExpectedResult = $"abc{"test"}/test";
var parameterTest1 = parser.ParseString("abc{parameter:TEST(T)}/test");
var parameterTest2 = parser.ParseString("abc{$test(T)}/test");
var resolvedWebpartId = parser.ParseString($"{{webpartid:{webPartTitle}}}");
var resolvedTermSetId = parser.ParseString($"{{termsetid:{termGroupName}:{termSetName}}}");
var resolvedTermStoreId = parser.ParseString($"{{termstoreid:{termStoreName}}}");
Assert.IsTrue(contentTypeId == resolvedContentTypeId);
Assert.IsTrue(listUrl == resolvedListUrl);
Guid outGuid;
Assert.IsTrue(Guid.TryParse(resolvedListId, out outGuid));
Assert.IsTrue(parameterTest1 == parameterExpectedResult);
Assert.IsTrue(parameterTest2 == parameterExpectedResult);
Assert.IsTrue(Guid.TryParse(resolvedWebpartId, out outGuid));
Assert.IsTrue(Guid.TryParse(resolvedTermSetId, out outGuid));
Assert.IsTrue(Guid.TryParse(resolvedTermStoreId, out outGuid));
}
}
示例10: CreateField
private static void CreateField(Web web, XElement templateFieldElement, PnPMonitoredScope scope, TokenParser parser, string originalFieldXml)
{
var listIdentifier = templateFieldElement.Attribute("List") != null ? templateFieldElement.Attribute("List").Value : null;
if (listIdentifier != null)
{
// Temporary remove list attribute from list
templateFieldElement.Attribute("List").Remove();
}
var fieldXml = parser.ParseString(templateFieldElement.ToString(), "~sitecollection", "~site");
if (IsFieldXmlValid(fieldXml, parser, web.Context))
{
var field = web.Fields.AddFieldAsXml(fieldXml, false, AddFieldOptions.AddFieldInternalNameHint);
web.Context.Load(field, f => f.TypeAsString, f => f.DefaultValue, f => f.InternalName, f => f.Title);
web.Context.ExecuteQueryRetry();
// Add newly created field to token set, this allows to create a field + use it in a formula in the same provisioning template
parser.AddToken(new FieldTitleToken(web, field.InternalName, field.Title));
bool isDirty = false;
#if !SP2013
if (originalFieldXml.ContainsResourceToken())
{
var originalFieldElement = XElement.Parse(originalFieldXml);
var nameAttributeValue = originalFieldElement.Attribute("DisplayName") != null ? originalFieldElement.Attribute("DisplayName").Value : "";
if (nameAttributeValue.ContainsResourceToken())
{
field.TitleResource.SetUserResourceValue(nameAttributeValue, parser);
isDirty = true;
}
var descriptionAttributeValue = originalFieldElement.Attribute("Description") != null ? originalFieldElement.Attribute("Description").Value : "";
if (descriptionAttributeValue.ContainsResourceToken())
{
field.DescriptionResource.SetUserResourceValue(descriptionAttributeValue, parser);
isDirty = true;
}
}
#endif
if (isDirty)
{
field.Update();
web.Context.ExecuteQueryRetry();
}
if ((field.TypeAsString == "TaxonomyFieldType" || field.TypeAsString == "TaxonomyFieldTypeMulti") && !string.IsNullOrEmpty(field.DefaultValue))
{
var taxField = web.Context.CastTo<TaxonomyField>(field);
ValidateTaxonomyFieldDefaultValue(taxField);
}
}
else
{
// The field Xml was found invalid
var tokenString = parser.GetLeftOverTokens(fieldXml).Aggregate(String.Empty, (acc, i) => acc + " " + i);
scope.LogError("The field was found invalid: {0}", tokenString);
throw new Exception(string.Format("The field was found invalid: {0}", tokenString));
}
}
示例11: ProvisionObjects
//.........这里部分代码省略.........
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Pages_Creating_new_page__0_, url);
web.AddWikiPageByUrl(url);
if (page.Layout == WikiPageLayout.Custom)
{
web.AddLayoutToWikiPage(WikiPageLayout.OneColumn, url);
}
else
{
web.AddLayoutToWikiPage(page.Layout, url);
}
}
catch (Exception ex)
{
scope.LogError(CoreResources.Provisioning_ObjectHandlers_Pages_Creating_new_page__0__failed___1_____2_, url, ex.Message, ex.StackTrace);
}
}
if (page.WelcomePage)
{
web.RootFolder.EnsureProperty(p => p.ServerRelativeUrl);
var rootFolderRelativeUrl = url.Substring(web.RootFolder.ServerRelativeUrl.Length);
web.SetHomePage(rootFolderRelativeUrl);
}
#if !SP2013
bool webPartsNeedLocalization = false;
#endif
if (page.WebParts != null & page.WebParts.Any())
{
if (!isNoScriptSite)
{
var existingWebParts = web.GetWebParts(url);
foreach (var webPart in page.WebParts)
{
if (existingWebParts.FirstOrDefault(w => w.WebPart.Title == parser.ParseString(webPart.Title)) == null)
{
WebPartEntity wpEntity = new WebPartEntity();
wpEntity.WebPartTitle = parser.ParseString(webPart.Title);
wpEntity.WebPartXml = parser.ParseString(webPart.Contents.Trim(new[] { '\n', ' ' }));
var wpd = web.AddWebPartToWikiPage(url, wpEntity, (int)webPart.Row, (int)webPart.Column, false);
#if !SP2013
if (webPart.Title.ContainsResourceToken())
{
// update data based on where it was added - needed in order to localize wp title
#if !SP2016
wpd.EnsureProperties(w => w.ZoneId, w => w.WebPart, w => w.WebPart.Properties);
webPart.Zone = wpd.ZoneId;
#else
wpd.EnsureProperties(w => w.WebPart, w => w.WebPart.Properties);
#endif
webPart.Order = (uint)wpd.WebPart.ZoneIndex;
webPartsNeedLocalization = true;
}
#endif
}
}
var allWebParts = web.GetWebParts(url);
foreach (var webpart in allWebParts)
{
parser.AddToken(new WebPartIdToken(web, webpart.WebPart.Title, webpart.Id));
}
}
else
{
scope.LogWarning(CoreResources.Provisioning_ObjectHandlers_Pages_SkipAddingWebParts, page.Url);
}
}
#if !SP2013
if (webPartsNeedLocalization)
{
page.LocalizeWebParts(web, parser, scope);
}
#endif
file = web.GetFileByServerRelativeUrl(url);
file.EnsureProperty(f => f.ListItemAllFields);
if (page.Fields.Any())
{
var item = file.ListItemAllFields;
foreach (var fieldValue in page.Fields)
{
item[fieldValue.Key] = parser.ParseString(fieldValue.Value);
}
item.Update();
web.Context.ExecuteQueryRetry();
}
if (page.Security != null && page.Security.RoleAssignments.Count != 0)
{
web.Context.Load(file.ListItemAllFields);
web.Context.ExecuteQueryRetry();
file.ListItemAllFields.SetSecurity(parser, page.Security);
}
}
}
return parser;
}
示例12: AddWebParts
//TODO: refactor this
private void AddWebParts(Web web, Page page, TokenParser parser)
{
var url = parser.ParseString(page.Url);
ContentPage contentPage = page as ContentPage;
if (contentPage != null)
{
var file = web.GetFileByServerRelativeUrl(url);
file.CheckOut();
foreach (var model in contentPage.WebParts)
{
try
{
model.Contents = parser.ParseString(model.Contents);
string oldId = null;
string newId = null;
if (!WebPartsModelProvider.IsV3FormatXml(model.Contents))
{
var id = WebPartsModelProvider.GetWebPartControlId(model.Contents);
var idToReplace = GetNewControlId();
model.Contents = model.Contents.Replace(id, idToReplace);
newId = this.GetIdFromControlId(idToReplace);
oldId = this.GetIdFromControlId(id);
}
var addedWebPart = this.AddWebPart(web, model, file);
newId = newId ?? addedWebPart.Id.ToString().ToLower();
oldId = oldId ?? GetWebPartIdFromSchema(model.Contents).ToLower();
parser.AddToken(new IdToken(web, newId, oldId));
}
catch (Exception ex)
{
Log.Error(Constants.LOGGING_SOURCE_FRAMEWORK_PROVISIONING, "Could not add webpart: {0} - {1}", ex.Message, ex.StackTrace);
}
}
var html = parser.ParseString(contentPage.Html);
if (!string.IsNullOrEmpty(html))
{
web.AddHtmlToWikiPage(url, html);
}
file.CheckIn(String.Empty, CheckinType.MajorCheckIn);
return;
}
}
示例13: CreateList
//.........这里部分代码省略.........
}
else
{
createdList.DraftVersionVisibility = (DraftVisibilityType)list.DraftVersionVisibility;
}
}
}
}
}
createdList.OnQuickLaunch = list.OnQuickLaunch;
if (createdList.BaseTemplate != (int)ListTemplateType.DiscussionBoard &&
createdList.BaseTemplate != (int)ListTemplateType.Events)
{
createdList.EnableFolderCreation = list.EnableFolderCreation;
}
createdList.Hidden = list.Hidden;
if (createdList.BaseTemplate != (int)ListTemplateType.Survey)
{
createdList.ContentTypesEnabled = list.ContentTypesEnabled;
}
createdList.Update();
web.Context.Load(createdList.Views);
web.Context.Load(createdList.Forms);
web.Context.Load(createdList, l => l.Id);
web.Context.Load(createdList, l => l.RootFolder.ServerRelativeUrl);
web.Context.Load(createdList, l => l.ContentTypesEnabled);
web.Context.Load(createdList.ContentTypes);
web.Context.ExecuteQueryRetry();
parser.AddToken(new ListIdProvisionToken(web, createdList.Id, list.ID));
parser.AddToken(new ListNameProvisionToken(web, createdList.Id, list.ID));
if (createdList.BaseTemplate != (int)ListTemplateType.Survey)
{
// Remove existing content types only if there are custom content type bindings
var contentTypesToRemove = new List<ContentType>();
if (list.RemoveExistingContentTypes && list.ContentTypeBindings.Count > 0)
{
contentTypesToRemove.AddRange(createdList.ContentTypes);
}
List<ContentType> listCTypes = new List<ContentType>();
listCTypes.AddRange(createdList.ContentTypes);
var contentTypeAdded = false;
ContentTypeBinding defaultCtBinding = null;
foreach (var ctBinding in list.ContentTypeBindings)
{
var contentType = web.AvailableContentTypes.AsEnumerable().FirstOrDefault(item => item.Id.StringValue.Equals(ctBinding.ContentTypeId, StringComparison.OrdinalIgnoreCase));
if (contentType != null)
{
// Check if CT is already available
var name = contentType.EnsureProperty(ct => ct.Name);
if (!listCTypes.Any( ct=> ct.Name == name ) )
{
if (createdList.ContentTypesEnabled == false)
{
createdList.ContentTypesEnabled = true;
createdList.Update();
createdList.Context.ExecuteQueryRetry();
}
示例14: UpdateList
private Tuple<List, TokenParser> UpdateList(Web web, List existingList, ListInstance templateList, TokenParser parser, PnPMonitoredScope scope, bool isNoScriptSite = false)
{
web.Context.Load(existingList,
l => l.Title,
l => l.Description,
l => l.OnQuickLaunch,
l => l.Hidden,
l => l.ContentTypesEnabled,
l => l.EnableAttachments,
l => l.EnableVersioning,
l => l.EnableFolderCreation,
l => l.EnableModeration,
l => l.EnableMinorVersions,
l => l.ForceCheckout,
l => l.DraftVersionVisibility,
l => l.Views,
l => l.DocumentTemplateUrl,
l => l.RootFolder,
l => l.BaseType,
l => l.BaseTemplate
#if !SP2013
, l => l.MajorWithMinorVersionsLimit
, l => l.MajorVersionLimit
#endif
);
web.Context.ExecuteQueryRetry();
if (existingList.BaseTemplate == templateList.TemplateType)
{
var isDirty = false;
if (parser.ParseString(templateList.Title) != existingList.Title)
{
var oldTitle = existingList.Title;
existingList.Title = parser.ParseString(templateList.Title);
if (!oldTitle.Equals(existingList.Title, StringComparison.OrdinalIgnoreCase))
{
parser.AddToken(new ListIdToken(web, existingList.Title, existingList.Id));
parser.AddToken(new ListUrlToken(web, existingList.Title, existingList.RootFolder.ServerRelativeUrl.Substring(web.ServerRelativeUrl.Length + 1)));
}
isDirty = true;
}
if (!string.IsNullOrEmpty(templateList.DocumentTemplate))
{
if (existingList.DocumentTemplateUrl != parser.ParseString(templateList.DocumentTemplate))
{
existingList.DocumentTemplateUrl = parser.ParseString(templateList.DocumentTemplate);
isDirty = true;
}
}
if (!string.IsNullOrEmpty(templateList.Description) && templateList.Description != existingList.Description)
{
existingList.Description = templateList.Description;
isDirty = true;
}
if (templateList.Hidden != existingList.Hidden)
{
existingList.Hidden = templateList.Hidden;
isDirty = true;
}
if (templateList.OnQuickLaunch != existingList.OnQuickLaunch)
{
existingList.OnQuickLaunch = templateList.OnQuickLaunch;
isDirty = true;
}
if (existingList.BaseTemplate != (int)ListTemplateType.Survey &&
templateList.ContentTypesEnabled != existingList.ContentTypesEnabled)
{
existingList.ContentTypesEnabled = templateList.ContentTypesEnabled;
isDirty = true;
}
if (existingList.BaseTemplate != (int)ListTemplateType.Survey &&
existingList.BaseTemplate != (int)ListTemplateType.DocumentLibrary &&
existingList.BaseTemplate != (int)ListTemplateType.PictureLibrary)
{
// https://msdn.microsoft.com/EN-US/library/microsoft.sharepoint.splist.enableattachments.aspx
// The EnableAttachments property does not apply to any list that has a base type of Survey, DocumentLibrary or PictureLibrary.
// If you set this property to true for either type of list, it throws an SPException.
if (templateList.EnableAttachments != existingList.EnableAttachments)
{
existingList.EnableAttachments = templateList.EnableAttachments;
isDirty = true;
}
}
if (existingList.BaseTemplate != (int)ListTemplateType.DiscussionBoard)
{
if (templateList.EnableFolderCreation != existingList.EnableFolderCreation)
{
existingList.EnableFolderCreation = templateList.EnableFolderCreation;
isDirty = true;
}
}
#if !SP2013
if (templateList.Title.ContainsResourceToken())
{
if (existingList.TitleResource.SetUserResourceValue(templateList.Title, parser))
{
isDirty = true;
}
}
#endif
//.........这里部分代码省略.........
示例15: CreateContentType
private static Microsoft.SharePoint.Client.ContentType CreateContentType(Web web, ContentType templateContentType, TokenParser parser, FileConnectorBase connector,
List<Microsoft.SharePoint.Client.ContentType> existingCTs = null, List<Microsoft.SharePoint.Client.Field> existingFields = null)
{
var name = parser.ParseString(templateContentType.Name);
var description = parser.ParseString(templateContentType.Description);
var id = parser.ParseString(templateContentType.Id);
var group = parser.ParseString(templateContentType.Group);
var createdCT = web.CreateContentType(name, description, id, group);
foreach (var fieldRef in templateContentType.FieldRefs)
{
var field = web.Fields.GetById(fieldRef.Id);
web.AddFieldToContentType(createdCT, field, fieldRef.Required, fieldRef.Hidden);
}
// Add new CTs
parser.AddToken(new ContentTypeIdToken(web, name, id));
#if !CLIENTSDKV15
// Set resources
if (templateContentType.Name.ContainsResourceToken())
{
createdCT.NameResource.SetUserResourceValue(templateContentType.Name, parser);
}
if(templateContentType.Description.ContainsResourceToken())
{
createdCT.DescriptionResource.SetUserResourceValue(templateContentType.Description, parser);
}
#endif
//Reorder the elements so that the new created Content Type has the same order as defined in the
//template. The order can be different if the new Content Type inherits from another Content Type.
//In this case the new Content Type has all field of the original Content Type and missing fields
//will be added at the end. To fix this issue we ordering the fields once more.
createdCT.FieldLinks.Reorder(templateContentType.FieldRefs.Select(fld => fld.Name).ToArray());
createdCT.ReadOnly = templateContentType.ReadOnly;
createdCT.Hidden = templateContentType.Hidden;
createdCT.Sealed = templateContentType.Sealed;
if (!string.IsNullOrEmpty(parser.ParseString(templateContentType.DocumentTemplate)))
{
createdCT.DocumentTemplate = parser.ParseString(templateContentType.DocumentTemplate);
}
if (!String.IsNullOrEmpty(templateContentType.NewFormUrl))
{
createdCT.NewFormUrl = templateContentType.NewFormUrl;
}
if (!String.IsNullOrEmpty(templateContentType.EditFormUrl))
{
createdCT.EditFormUrl = templateContentType.EditFormUrl;
}
if (!String.IsNullOrEmpty(templateContentType.DisplayFormUrl))
{
createdCT.DisplayFormUrl = templateContentType.DisplayFormUrl;
}
createdCT.Update(true);
web.Context.ExecuteQueryRetry();
// If the CT is a DocumentSet
if (templateContentType.DocumentSetTemplate != null)
{
// Retrieve a reference to the DocumentSet Content Type
Microsoft.SharePoint.Client.DocumentSet.DocumentSetTemplate documentSetTemplate =
Microsoft.SharePoint.Client.DocumentSet.DocumentSetTemplate.GetDocumentSetTemplate(web.Context, createdCT);
if (!String.IsNullOrEmpty(templateContentType.DocumentSetTemplate.WelcomePage))
{
// TODO: Customize the WelcomePage of the DocumentSet
}
foreach (String ctId in templateContentType.DocumentSetTemplate.AllowedContentTypes)
{
Microsoft.SharePoint.Client.ContentType ct = existingCTs.FirstOrDefault(c => c.StringId == ctId);
if (ct != null)
{
documentSetTemplate.AllowedContentTypes.Add(ct.Id);
}
}
foreach (var doc in templateContentType.DocumentSetTemplate.DefaultDocuments)
{
Microsoft.SharePoint.Client.ContentType ct = existingCTs.FirstOrDefault(c => c.StringId == doc.ContentTypeId);
if (ct != null)
{
using (Stream fileStream = connector.GetFileStream(doc.FileSourcePath))
{
documentSetTemplate.DefaultDocuments.Add(doc.Name, ct.Id, ReadFullStream(fileStream));
}
}
}
foreach (var sharedField in templateContentType.DocumentSetTemplate.SharedFields)
{
Microsoft.SharePoint.Client.Field field = existingFields.FirstOrDefault(f => f.Id == sharedField);
if (field != null)
{
documentSetTemplate.SharedFields.Add(field);
}
}
//.........这里部分代码省略.........