我有自定义sharepoint网站xml模板。
当我根据我的网站模板创建自定义网站时,sharepoint。 功能包括:
<Feature ID="22A9EF51-737B-4ff2-9346-694633FE4416">
<!-- Publishing -->
<Properties xmlns="http://schemas.microsoft.com/sharepoint/">
<!--<Property Key="ChromeMasterUrl" Value="~SiteCollection/_catalogs/masterpage/my.master" />-->
<Property Key="WelcomePageUrl" Value="$Resources:osrvcore,List_Pages_UrlName;/default.aspx" />
<Property Key="PagesListUrl" Value="" />
<Property Key="SimplePublishing" Value="true" />
<!--<Property Key="DefaultPageLayout" Value="~SiteCollection/_catalogs/masterpage/my.aspx"/>-->
<Property Key="EnableApprovalWorkflowOnDocuments" Value="false"/>
<Property Key="EnableApprovalWorkflowOnImages" Value="false"/>
<Property Key="EnableApprovalWorkflowOnPages" Value="false"/>
<Property Key="EnableModerationOnDocuments" Value="false"/>
<Property Key="EnableModerationOnImages" Value="false"/>
<Property Key="EnableModerationOnPages" Value="true"/>
<Property Key="EnableSchedulingOnDocuments" Value="false"/>
<Property Key="EnableSchedulingOnImages" Value="false"/>
<Property Key="EnableSchedulingOnPages" Value="true"/>
<Property Key="RequireCheckoutOnDocuments" Value="false"/>
<Property Key="RequireCheckoutOnImages" Value="false"/>
<Property Key="RequireCheckoutOnPages" Value="false"/>
<Property Key="VersioningOnPages" Value="MajorAndMinor"/>
</Properties>
</Feature>
<Feature ID="541F5F57-C847-4e16-B59A-B31E90E6F9EA">
<!-- Per-Web Portal Navigation Properties-->
<Properties xmlns="http://schemas.microsoft.com/sharepoint/">
<Property Key="InheritGlobalNavigation" Value="false"/>
<Property Key="IncludeSubSites" Value="false"/>
<Property Key="IncludePages" Value="false"/>
</Properties>
</Feature>
我有功能,我正在尝试添加节点:
private void ProvisionQuickLaunchLinks(SPWeb web)
{
var serverUrl = web.ServerRelativeUrl;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite impSite = new SPSite(web.Site.ID))
{
RemoveExistingNodes(web, impSite);
using (SPWeb impWeb = impSite.OpenWeb(web.ID))
{
if (impWeb != null && impWeb.Exists)
{
try
{
var isRoot = SiteHelper.GetIsProjectRootSite(web);
impWeb.AllowUnsafeUpdates = true;
AddQuickLink(impWeb, "My link", "/Lists/MyList/Forms/AllItems.aspx", Constants.Navigation.NavigationLinkKey, "/_layouts/temp/temp/img/menu_icon3.png");
impWeb.Update();
}
catch (Exception ex)
{
LoggingService.WriteError(ex, "Cannot remove links to navigation menu");
}
finally
{
if (impWeb != null)
{
impWeb.AllowUnsafeUpdates = false;
}
}
}
}
}
});
}
在添加之前我将删除所有内容:
private static void RemoveExistingNodes(SPWeb web, SPSite impSite)
{
using (SPWeb impWeb = impSite.OpenWeb(web.ID))
{
if (impWeb != null && impWeb.Exists)
{
try
{
var isRoot = SiteHelper.GetIsProjectRootSite(web);
impWeb.AllowUnsafeUpdates = true;
var quicklaunchCollection = impWeb.Navigation.QuickLaunch;
foreach (SPNavigationNode tempNode in quicklaunchCollection)
{
impWeb.Navigation.QuickLaunch.Delete(tempNode);
impWeb.Update();
}
}
catch (Exception ex)
{
LoggingService.WriteError(ex, "Cannot remove links to navigation menu");
}
finally
{
if (impWeb != null)
{
impWeb.AllowUnsafeUpdates = false;
}
}
}
}
}
创建网站后,我不仅有我的链接,还有“网站”和“列表”! 但我不想拥有那些!请建议如何删除它们!
答案 0 :(得分:2)
foreach循环是错误的。使用:
for(int i = quicklaunchCollection.Count - 1; i >= 0; i--)
{
quicklaunchCollection[i].Delete();
}