gpt4 book ai didi

sharepoint - 如何访问Sharepoint SPNavigationNode.QuickLaunch属性?

转载 作者:行者123 更新时间:2023-12-04 18:28:37 24 4
gpt4 key购买 nike

我有一个网站,如下所示:

--SiteA
---- Subsite1
---- Subsite2

现在每当我尝试访问QuickLaunch属性时,它始终为空,例如

SPNavigation nav = spWeb.Navigation;
if (nav.QuickLaunch.Count == 0)
{
// ALWAYS TRUE
}


但是,如果我进入SiteA的“导航设置”(通过UI)并重新排序列表中的任何站点,则只有QuickLanuch可用。 (其他设置保留为默认设置)

谁能解释这种行为?我确实需要访问QuickLaunch项目。

谢谢

最佳答案

如果在创建网站时访问quicklaunch,则会发生此错误。下面的代码使功能激活的代码等待,直到创建网站集之后再执行。

using System.Threading;


public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
//Queues changes until after site exists. For use in provisioning.
SPWeb web = properties.Feature.Parent as SPWeb;
ThreadPool.QueueUserWorkItem(ApplyYourChanges, web.Url);
}

private void ApplyYourChanges(object state)
{
string webUrl = state as string;
Uri uri = new Uri(webUrl);

// additional conditions here -- perhaps check if a feature was activated
while (!SPSite.Exists(uri))
{
Thread.Sleep(5000);
}
using (SPSite site = new SPSite(webUrl))
{
using (SPWeb web = site.OpenWeb())
{
//configure the quicklaunch menu
configureQuickLaunch(web);
}
}
}

public static void configureQuickLaunch(SPWeb spWeb)
{
SPNavigationNodeCollection nodeCollection = spWeb.Navigation.QuickLaunch;
SPNavigationNode heading = nodeCollection.Cast<SPNavigationNode>().FirstOrDefault(n => n.Title == headingNode);
SPNavigationNode item = heading.Children.Cast<SPNavigationNode>().FirstOrDefault(n => n.Url == url);
if(item == null)
{
item = new SPNavigationNode(nodeName, url);
item = heading.Children.AddAsLast(item);
}
}

关于sharepoint - 如何访问Sharepoint SPNavigationNode.QuickLaunch属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/676155/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com