none
关于alerts的问题 RRS feed

  • 问题

  •                 SPSecurity.RunWithElevatedPrivileges(delegate()
                    {
                        using (SPSite site = new SPSite(url))
                        {
                            using (SPWeb web = site.OpenWeb(new Guid(ViewState["groupid"].ToString())))
                            {
                                SPUser user = SPContext.Current.Web.CurrentUser;                           
                                web.AllowUnsafeUpdates = true;
                               
                                Guid wikiGuid = new Guid(ViewState["wid"].ToString());
                                SPList list = web.Lists[wikiGuid];
                                SPListItem item = list.GetItemById(itemid);
                                SPAlert a = user.Alerts.Add();
                                a.Title = list.Title + ":" + item.Name;
                                a.Status = SPAlertStatus.On;
                                a.EventType = SPEventType.All;
                                a.AlertType = SPAlertType.Item;
                                a.AlertFrequency = SPAlertFrequency.Immediate;
                                a.Item = item;//单独写个测试demo完全没有问题,但是在正式项目里面这句话会抛出下面的异常,这是为什么
                                a.Update();

                             //web.Update();
                            }
                        }
                    });

    SPException was unhandled by user code

    List does not exist

    The page you selected contains a list that does not exist.  It may have been deleted by another user.

     

    我不知道这是问什么,但是这个list和page肯定是存在的

    2010年7月13日 8:08

全部回复

  • 我发现了 spuser必须这样获取才能添加alerts

    SPUser user = web.AllUsers[SPContext.Current.Web.CurrentUser.LoginName];

    这是为什么?

     根据LoginName去找他自己?

    2010年7月13日 8:42