SPNavigationNode Id属性不应将int32作为类型,字符串会更好 [英] SPNavigationNode Id property should not has int32 as type, string would be better

查看:87
本文介绍了SPNavigationNode Id属性不应将int32作为类型,字符串会更好的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为SharePoint开发自定义站点地图提供程序,用委托控件替换默认的站点快速启动和全局导航.

sitemapprovider从第三方LOB系统读取数据.我希望用户能够通过编辑快速启动和全局导航来覆盖LOB系统中的sitemapnode数据,也就是说,使sitemapprovider为可编辑的".

我想将用户编辑结果存储在OOTB spweb.navigation中.因此,我需要在sitemapprovider的sitemapnode和SPNavigationNode之间建立一对一的关系. SiteMapNode具有字符串类型的Key属性,我可以使用 指导为它的字符串.但是,SPNavigationNode的ID是Int32.

在SiteMapProvider代码中,我无法确定在何处使用了提供程序,快速启动栏或topnavigationbar,可以吗?因此,我不能使用SPWeb.Navigation.QuickLaunch.Navigation.GetNodeById.我只能使用SPWeb.Navigation.GetNodeById.但这是一个很好的机会 则不同提供商中的SiteMapNode将具有相同的int32 ID.

如果我使用GetNodeByTitle,我想多语言会让事情变得复杂.

更新:字符串比Guid更灵活,更新了线程标题.

更新: https://msdn.microsoft.com/zh-cn/library/office/microsoft.sharepoint.navigation.editableaspmenunode.key.aspx  好像 适合我的要求,但尚未找到如何使用此editableaspmenunode类的示例.


解决方案

以PortalSiteMapProvider为例,

私有SPNavigationNode GetSPNavigationNode(字符串键)

在这个问题上,方法有一些不足之处.

EditableASPMenuNode中的键的格式设置为?SPNavigationNodeId = xxx",而xxx是SPNavigationNode的ID

更新:仍然感到困惑.我猜想?SPNavigationNodeId ="字符串将是sitemapprovider特定的,因此可以将来自不同来源的SPNavigationNode混合在同一EditableASPMenuNode集合中.但是,在GetSPNavigationNode方法中, 得到了xxx ID,它仍然使用SPWeb.Navigation.GetNodeById(xxx)查找得到SPNavigationNode,如果QuickLaunch.Navigation和TopNavigation.Navigation中都具有相同的ID,该怎么办.

实际上,我发现PortalSiteMapProvider.SaveUpdatededMenuState使用StartingNodeKey 1025或1002来告诉它是在TopNavigation还是QuickLaunch中使用的. StartingNodeKey似乎可以在ASPMenu控件中指定.

简而言之,PortalSiteMapProvider.GetSPNavigationNode方法可能会为EditableASPMenuNode获取错误的SPNavigationNode.我还没有测试它,只是通过代码审查来推断.

我的DEV环境中的SharePoint版本为15.0.4841.1000


i am developing custom sitemapproviders for SharePoint, replace the default site quicklaunch and globalnavigation with delegatecontrols.

the sitemapprovider read data from third party LOB systems. And i would like the user to be able to override the sitemapnode data from LOB systems by editing the quicklaunch and globalnavigation, that is, make the sitemapprovider "editable".

I want to store the user editing results in OOTB spweb.navigation. Therefore, i need to establish one-to-one relationship between sitemapnode from sitemapprovider and SPNavigationNode. The SiteMapNode has Key property of string type, i can use Guid as string for it. But, the Id for SPNavigationNode is Int32. 

In SiteMapProvider code, i cannot tell where the provider is used, quicklaunch or topnavigationbar, can I? So, i cannot use SPWeb.Navigation.QuickLaunch.Navigation.GetNodeById. I can only use SPWeb.Navigation.GetNodeById. But it would be a good chance that SiteMapNode in different providers would have the same int32 Id. 

And if i use the GetNodeByTitle, i guess multi-lingual would make things complicated.

update: String would be more flexible than Guid,updated the thread title.

update: https://msdn.microsoft.com/en-us/library/office/microsoft.sharepoint.navigation.editableaspmenunode.key.aspx   seems suitable for my requirement, but has not found sample on how to use this editableaspmenunode class yet.


解决方案

use PortalSiteMapProvider as example and the 

private SPNavigationNode GetSPNavigationNode(string key)

method shade some light on this issue.

the Key in EditableASPMenuNode is formatted as something like "?SPNavigationNodeId=xxx", and xxx is the Id of SPNavigationNode

update: still confused. I guess that the "?SPNavigationNodeId=" string will be sitemapprovider specific, so that SPNavigationNode from different origin can be mixed in the same EditableASPMenuNode collection. however, in GetSPNavigationNode method, after got the xxx id, it still use SPWeb.Navigation.GetNodeById(xxx) to find get the SPNavigationNode, what if there will be same id in both QuickLaunch.Navigation and TopNavigation.Navigation.

actually, I found that PortalSiteMapProvider.SaveUpdatededMenuState use the StartingNodeKey 1025 or 1002 to tell whether it is used in TopNavigation or QuickLaunch. StartingNodeKey seems to be something which can be specified in ASPMenu control. 

In short, PortalSiteMapProvider.GetSPNavigationNode method can possibly get the wrong SPNavigationNode for EditableASPMenuNode. I have not tested it, just infer by code review.

The SharePoint build in my DEV environment is 15.0.4841.1000


这篇关于SPNavigationNode Id属性不应将int32作为类型,字符串会更好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆