以编程方式更新 moss 中导航节点的 url
任何人都可以明白为什么这不应该工作:
SPSite topNavigationSite = new SPSite("http://moss");
SPWeb topNavigationWeb = topNavigationSite.OpenWeb();
SPNavigationNodeCollection topNavigationBarNodes = topNavigationWeb.Navigation.TopNavigationBar;
SPNavigationNode updateNode = topNavigationBarNodes.Navigation.GetNodeByUrl("/about");
updateNode.Url = "";
topNavigationWeb.Update();
我可以看到调试 url get 设置为“”,但是当页面呈现时,导航仍然将 url 显示为 /about/default.aspx
我正在 page_load 中运行它并期望它使用新的 url 值更新 moss 数据库。
Can anyone see why this should not work:
SPSite topNavigationSite = new SPSite("http://moss");
SPWeb topNavigationWeb = topNavigationSite.OpenWeb();
SPNavigationNodeCollection topNavigationBarNodes = topNavigationWeb.Navigation.TopNavigationBar;
SPNavigationNode updateNode = topNavigationBarNodes.Navigation.GetNodeByUrl("/about");
updateNode.Url = "";
topNavigationWeb.Update();
I can see debugging that the url get's set to "" but when the page renders, the navigation still shows the url as /about/default.aspx
I'm running this in page_load and expected it to update the moss database with the new url value.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我知道这已经3岁了!但因为网上没有关于更新当前网址的地方!
我必须进行一些调试,这就是 iv 得出的结果!顺便说一下,我得到了提示
,表明它正在更新列表!提示提示!
一点背景知识!我想在列表中添加、更新和删除项目时更新列表中的快速链接!在我的列表中,有两列“标题”和“URL”!
然后我在 VS 2010 中创建了一个项目,它是一个事件接收器,仅连接到
.cs 文件中的该列表(在 elements.xml 文件中完成),我添加了项目添加、项目删除(未删除;))和项目更新
public override void ItemAdded(SPItemEventPropertiesproperties)
public override void ItemUpdated(SPItemEventPropertiesproperties)
public override void ItemDeleting(SPItemEventPropertiesproperties)
现在,在每个方法中,您可以简单地调用此方法!
添加/更新
第一部分是使用标题(标题)检查节点是否存在!我正在比较标题和列表项中的标题:
这部分是比较:
我得到这些值(标题和 url / spweb),如下所示:
public static void AddQuickLaunchItem(string header, string url, SPWeb web )
调用上面的方法将如下所示:
并且上面的方法在 itemadded 和 itemupdated 中调用;) 像这样传递值:
可以为删除执行类似的操作;)
SPNavigationNode nodeHeader =
QuickLaunch.Cast().Where(n => n.Title == header).FirstOrDefault();
这将获得节点!
nodeHeader.delete();
节点头.update();
这将删除该项目!
所以在你的情况下你需要什么,我不知道你是否注意到这是这一部分:
正如你所看到的,我的提示是什么意思!节点标题.Update();没有更新网址,调试时它确实发生了变化,但是当我转到更新部分时它不起作用:(并且它点击了我需要
web.AllowUnsafeUpdates = true;
loool只是因为我经历了类似的情况之前!对于您来说,这将是:
如果用户没有足够的权限,那么您需要使用 runwithelevatedprivalages 封装上述内容:)希望这会有所帮助:)
I know this is 3years old! but as there is no where online about updating a current url!
I had to do some debugging and this is what iv come up with! By the way I got the hint from
indicating that its updating a list! hint hint!
a bit of background! I wanted to update the quick links from a list when they add, update and delete an item from the list! On my list I have two columns Title and URL!
I then created a project in VS 2010, its an event receiver that is connected only to that list (done in the elements.xml file)
within the .cs file I added item added, item deleting(not deleted ;) ) and item updated
public override void ItemAdded(SPItemEventProperties properties)
public override void ItemUpdated(SPItemEventProperties properties)
public override void ItemDeleting(SPItemEventProperties properties)
now within each method you can simply call this method!
add/update
the first part is checking if the node exists using the title (header)! I'm comparing between what headers there are and from the list item:
this part is the comparison:
I'm getting these values (header and url / spweb) like so:
public static void AddQuickLaunchItem(string header, string url, SPWeb web)
the method that is calling the above would look like this:
and the above method is called within the itemadded and itemupdated ;) passing the values like so:
similar things can be done for the delete ;)
SPNavigationNode nodeHeader =
quickLaunch.Cast().Where(n => n.Title == header).FirstOrDefault();
that will get the node!
nodeHeader.delete();
nodeHeader.update();
that will delete the item!
so in your case what you need, I don't know if you noticed it was this part:
as you can see what i mean by the hint! nodeHeader.Update(); didnt update the url, when debugging it does change but when i go to the update part it doesnt work :( and it clicked in i need
web.AllowUnsafeUpdates = true;
loool only becuse I experienced a similar situation before!for you it would be:
If the user doesnt have the sufficent rights than you need to encapsulate the above with runwithelevatedprivalages :) hope this helps :)
您是否尝试过:
您似乎没有更新 SPNavigationNode 对象。 (注意:您可能不需要第二次 Update 调用。)
Have you tried:
It doesn't look like you are updating the SPNavigationNode object. (Note: you may not need the second Update call.)