如何以编程方式重命名 Sharepoint 目录(SPFolder 或 SPListItem)?
我已经尝试过这个:
SPFolder folder = ...;
folder.Item["Name"] = newName;
folder.Item.Update();
它的行为很神秘。如果我运行它,它会抛出异常:
SPException: Cannot complete this action.
但是,如果我在新名称分配之后和 Update() 之前在调试器中停止它,并查看folder.Item的属性,然后继续,它每次都会起作用。这不是一个计时问题,我尝试在调试器中停止它,而不在“本地”窗口中查看它,但当时它引发了异常。
这个问题表明了类似的解决方案,但使用 SystemUpdate(),这有关系吗? 以编程方式更改 SPFolder 的名称
I have tried this:
SPFolder folder = ...;
folder.Item["Name"] = newName;
folder.Item.Update();
And it behaves mysteriously. If I run it, it throws an exception:
SPException: Cannot complete this action.
HOWEVER, if I stop it in the debugger after the new Name assignment and before the Update(), and look at the properties of folder.Item, then continue, it works every time. It's not a timing thing, I tried stopping it in the debugger without looking at it in the Locals window, but it threw an exception that time.
This question indicates a similar solution but using SystemUpdate(), does that matter? Programmatically changing name of SPFolder
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
在
文档库
中,项目(文件夹)的Name
字段具有StaticName = FileLeafRef
。所以真正对我有用的是In a
Document Library
the fieldName
of an item (folder) hasStaticName = FileLeafRef
. So what really worked for me is您不需要更改名称,但需要更改标题。
所以:
Update 和 SystemUpdate 之间的区别在于 Update 会更改修改/修改的信息,如果启用版本控制,则会增加版本号。 SystemUpdate 不会更新这些。
另请注意,我使用 SPBuiltInFieldId.Title。这比使用“标题”更好,因为“标题”可能会导致非英文网站出现问题。
You do not need to change the name, but te title.
So:
The difference between Update and SystemUpdate is that Update will change modified / modified by information and if versioning is enabled it will increase the version number. SystemUpdate does not update these.
Also note that I use SPBuiltInFieldId.Title. This is better than using "Title", because "Title" may cause issues in sites that are not in English.
尝试在操作“folder.ParentWeb.AllowUnsafeUpdates = true”之前添加
然后将AllowUnsafeUpdates恢复到之前的值。
Try to add before the action "folder.ParentWeb.AllowUnsafeUpdates = true"
and after it bring back the AllowUnsafeUpdates to it's previous value.
您可以尝试使用
MoveTo
方法You can try using the
MoveTo
method这把叉子给我
this fork for me