积极答复者
通过代码操作共享点 创建讨论版里面的帖子和回复

问题
-
public void Test() { SPSite site = new SPSite("http://jianghao:9000"); SPWeb web = site.OpenWeb(); using (site) { using (web) { web.AllowUnsafeUpdates = true; SPList list = web.Lists["Revolution"]; //创建帖子 SPListItem newItem = SPUtility.CreateNewDiscussion(list.Items, "THIS IS MY TEST 2!"); newItem["Body"] = "Welcome to My Discassion2!"; newItem.Update(); //创建回复信息 SPListItem newItemReply = SPUtility.CreateNewDiscussionReply(newItem); newItemReply["Body"] = "My reply this message!"; newItemReply.Update(); // Operation is not valid due to the current state of the object } } }
newItemReply.Update(); // Operation is not valid due to the current state of the object.
前面的都执行成功了!
就是执行到这里报Operation is not valid due to the current state of the object这个错误!
thanks!
Anything Is Possible !
答案
-
上面的代码在我的机器上执行成功,你试试加上 SPSecurity.RunWithElevatedPrivileges
SPSecurity.RunWithElevatedPrivileges(delegate() {
SPSite site = new SPSite("http://jianghao:9000");
SPWeb web = site.OpenWeb();
using (site)
//...
});
Hope Helpful | Xiaofeng Wang | http://www.leoworks.net | Beijing P.R.C- 已标记为答案 Jiang Hao 2010年1月25日 1:22
全部回复
-
上面的代码在我的机器上执行成功,你试试加上 SPSecurity.RunWithElevatedPrivileges
SPSecurity.RunWithElevatedPrivileges(delegate() {
SPSite site = new SPSite("http://jianghao:9000");
SPWeb web = site.OpenWeb();
using (site)
//...
});
Hope Helpful | Xiaofeng Wang | http://www.leoworks.net | Beijing P.R.C- 已标记为答案 Jiang Hao 2010年1月25日 1:22