SharePoitn 2010 获取用户 alert 然后删除alert

For anyone that is interested, I figured it out:

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
using System.Data;
using System.Collections.Specialized;
using System.Collections;
using Microsoft.SharePoint;

 

namespace ConfirmationModal.TestModal
{
    public partial class TestModalUserControl : UserControl
    {
        String site = SPContext.Current.Web.Url;

        protected void Page_Load(object sender, EventArgs e)
        {
            GridView1.DataSource = this.GetAlerts();
           // GridView1.Columns[2].Visible = true;
            GridView1.DataBind();
            //GridView1.Columns[2].Visible = false;
        }

        private DataTable GetAlerts()
        {
            using (SPSite site = new SPSite(this.site))
            {
                using (SPWeb web = site.RootWeb)
                {
                    SPUser user = SPContext.Current.Web.CurrentUser;

                    DataTable table = new DataTable();
                    table.Columns.Add("Title", typeof(string));
                    table.Columns.Add("AlertID", typeof(string));

                    //SPUser user = web.EnsureUser(@"domainName\userName");

                    SPAlertCollection alertColl = user.Alerts;
                    DataRow row;

                    foreach (SPAlert alert in alertColl)
                    {
                        try
                        {
                            row = table.Rows.Add();
                            row["Title"] = alert.Title.ToString();
                            row["AlertID"] = alert.ID.ToString(); //Hide


                            //table.Rows.Add(row);
                        }
                        catch (Exception ex)
                        {
                            ex.StackTrace.ToString();
                        }
                    }

                    return table;
                }
            }
        }


你可能感兴趣的:(alert)