我收到了这段代码
PublishingPage newPage = pWeb.GetPublishingPages().Add(fileName, layout);
newPage.Title = title;
但是,如果页面存在,则会抛出异常,我想在
之前检查它是否存在答案 0 :(得分:4)
你可以试试这个:
SPWeb web = properties.Feature.Parent as SPWeb;
PublishingWeb pWeb = PublishingWeb.GetPublishingWeb(web);
foreach (PublishingPage page in pWeb.GetPublishingPages())
{
if (page.Name.Equals("myPage.aspx"))
{
// Do your stuff here
}
}
或者如果你发现它不够快,你可以试试这个:
pWeb.GetPublishingPages().ToList().Find(x => x.Name.Equals(filename))