本文整理汇总了C#中Web.GetWebPartXml方法的典型用法代码示例。如果您正苦于以下问题:C# Web.GetWebPartXml方法的具体用法?C# Web.GetWebPartXml怎么用?C# Web.GetWebPartXml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Web
的用法示例。
在下文中一共展示了Web.GetWebPartXml方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExtractObjects
public override ProvisioningTemplate ExtractObjects(Web web, ProvisioningTemplate template, ProvisioningTemplateCreationInformation creationInfo)
{
using (var scope = new PnPMonitoredScope(this.Name))
{
// Extract the Home Page
web.EnsureProperties(w => w.RootFolder.WelcomePage, w => w.ServerRelativeUrl, w => w.Url);
var homepageUrl = web.RootFolder.WelcomePage;
if (string.IsNullOrEmpty(homepageUrl))
{
homepageUrl = "Default.aspx";
}
var welcomePageUrl = UrlUtility.Combine(web.ServerRelativeUrl, homepageUrl);
var file = web.GetFileByServerRelativeUrl(welcomePageUrl);
try
{
var listItem = file.EnsureProperty(f => f.ListItemAllFields);
if (listItem != null)
{
if (listItem.FieldValues.ContainsKey("WikiField"))
{
// Wiki page
var fullUri = new Uri(UrlUtility.Combine(web.Url, web.RootFolder.WelcomePage));
var folderPath = fullUri.Segments.Take(fullUri.Segments.Count() - 1).ToArray().Aggregate((i, x) => i + x).TrimEnd('/');
var fileName = fullUri.Segments[fullUri.Segments.Count() - 1];
var homeFile = web.GetFileByServerRelativeUrl(welcomePageUrl);
LimitedWebPartManager limitedWPManager =
homeFile.GetLimitedWebPartManager(PersonalizationScope.Shared);
web.Context.Load(limitedWPManager);
var webParts = web.GetWebParts(welcomePageUrl);
var page = new Page()
{
Layout = WikiPageLayout.Custom,
Overwrite = true,
Url = Tokenize(fullUri.PathAndQuery, web.Url),
};
var pageContents = listItem.FieldValues["WikiField"].ToString();
Regex regexClientIds = new Regex(@"id=\""div_(?<ControlId>(\w|\-)+)");
if (regexClientIds.IsMatch(pageContents))
{
foreach (Match webPartMatch in regexClientIds.Matches(pageContents))
{
String serverSideControlId = webPartMatch.Groups["ControlId"].Value;
try
{
String serverSideControlIdToSearchFor = String.Format("g_{0}",
serverSideControlId.Replace("-", "_"));
WebPartDefinition webPart = limitedWPManager.WebParts.GetByControlId(serverSideControlIdToSearchFor);
web.Context.Load(webPart,
wp => wp.Id,
wp => wp.WebPart.Title,
wp => wp.WebPart.ZoneIndex
);
web.Context.ExecuteQueryRetry();
var webPartxml = TokenizeWebPartXml(web, web.GetWebPartXml(webPart.Id, welcomePageUrl));
page.WebParts.Add(new Model.WebPart()
{
Title = webPart.WebPart.Title,
Contents = webPartxml,
Order = (uint)webPart.WebPart.ZoneIndex,
Row = 1, // By default we will create a onecolumn layout, add the webpart to it, and later replace the wikifield on the page to position the webparts correctly.
Column = 1 // By default we will create a onecolumn layout, add the webpart to it, and later replace the wikifield on the page to position the webparts correctly.
});
pageContents = Regex.Replace(pageContents, serverSideControlId, string.Format("{{webpartid:{0}}}", webPart.WebPart.Title), RegexOptions.IgnoreCase);
}
catch (ServerException)
{
scope.LogWarning("Found a WebPart ID which is not available on the server-side. ID: {0}", serverSideControlId);
}
}
}
page.Fields.Add("WikiField", pageContents);
template.Pages.Add(page);
// Set the homepage
if (template.WebSettings == null)
{
template.WebSettings = new WebSettings();
}
template.WebSettings.WelcomePage = homepageUrl;
}
else
{
if (web.Context.HasMinimalServerLibraryVersion(Constants.MINIMUMZONEIDREQUIREDSERVERVERSION))
{
//.........这里部分代码省略.........
示例2: GetFileContents
private ProvisioningTemplate GetFileContents(Web web, ProvisioningTemplate template, string welcomePageUrl, ProvisioningTemplateCreationInformation creationInfo, PnPMonitoredScope scope)
{
var fullUri = new Uri(UrlUtility.Combine(web.Url, web.RootFolder.WelcomePage));
var folderPath = fullUri.Segments.Take(fullUri.Segments.Count() - 1).ToArray().Aggregate((i, x) => i + x).TrimEnd('/');
var fileName = fullUri.Segments[fullUri.Segments.Count() - 1];
var webParts = web.GetWebParts(welcomePageUrl);
var file = web.GetFileByServerRelativeUrl(welcomePageUrl);
var homeFile = new Model.File()
{
Folder = Tokenize(folderPath, web.Url),
Src = fileName,
Overwrite = true,
};
// Add field values to file
RetrieveFieldValues(web, file, homeFile);
// Add WebParts to file
foreach (var webPart in webParts)
{
var webPartxml = TokenizeWebPartXml(web, web.GetWebPartXml(webPart.Id, welcomePageUrl));
Model.WebPart newWp = new Model.WebPart()
{
Title = webPart.WebPart.Title,
Row = (uint)webPart.WebPart.ZoneIndex,
Contents = webPartxml
};
#if !CLIENTSDKV15
// As long as we've no CSOM library that has the ZoneID we can't use the version check as things don't compile...
if (web.Context.HasMinimalServerLibraryVersion(Constants.MINIMUMZONEIDREQUIREDSERVERVERSION))
{
newWp.Zone = webPart.ZoneId;
}
#endif
homeFile.WebParts.Add(newWp);
}
template.Files.Add(homeFile);
// Persist file using connector
if (creationInfo.PersistBrandingFiles)
{
PersistFile(web, creationInfo, scope, folderPath, fileName);
}
return template;
}