none
Mail notification in sharepoint RRS feed

  • 問題

  • Sharepoint 裏, 一次只能 一個人接收到mail notification, 請問有沒什麼方法,  可以做到一個task, 可以多人收到mail notification?

    謝謝

    2006年12月14日 上午 08:48

解答

所有回覆

  • Dear Sophia_Kuan:

    2003 Portal 中預設情況下沒有辦法多人接收, 這版本中主要的定位在於[個人], 也就是說, Alert 這一個功能是端看個人是否需要再經由個人自行設定, 但是如果要做您的需求的話, 可以克制化網頁組件

    2006年12月14日 上午 09:34
  • 請問要如何客制化呢?
    2006年12月14日 上午 10:21
  • Dear Sophia_Kuan:

    寫網頁組件...

    using System;
    using System.ComponentModel;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Xml.Serialization;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.Utilities;
    using Microsoft.SharePoint.WebPartPages;
    using Microsoft.SharePoint.WebControls;
    using Microsoft.SharePoint.Dsp;
    using Microsoft.SharePoint.Library;
    using Microsoft.SharePoint.Security;

    namespace vanGeneSendAlertsToAllUser
    {
     /// <summary>
     /// Description for SendAlertsToAllUser.
     /// </summary>
     [DefaultProperty("Text"),
      ToolboxData("<{0}:SendAlertsToAllUser runat=server></{0}:SendAlertsToAllUser>"),
      XmlRoot(Namespace="vanGeneSendAlertsToAllUser")]
     public class SendAlertsToAllUser : Microsoft.SharePoint.WebPartPages.WebPart
     {
      DropDownList listList;
      ListBox alertList;
      DropDownList userList;

      LinkButton addAllAlerts;
      LinkButton addAlert;

      RadioButton alertTypeAll;
      RadioButton alertTypeAdded;
      RadioButton alertTypeChanged;
      RadioButton alertTypeDeleted;

    //  private const string defaultText = "";
    //
    //  private string text = defaultText;
    //
    //  [Browsable(true),
    //   Category("Miscellaneous"),
    //   DefaultValue(defaultText),
    //   WebPartStorage(Storage.Personal),
    //   FriendlyName("Text"),
    //   Description("Text Property")]
    //  public string Text
    //  {
    //   get
    //   {
    //    return text;
    //   }
    //
    //   set
    //   {
    //    text = value;
    //   }
    //  }
      
      /// <summary>
      /// This method gets the custom tool parts for this Web Part by overriding the
      /// GetToolParts method of the WebPart base class. You must implement
      /// custom tool parts in a separate class that derives from
      /// Microsoft.SharePoint.WebPartPages.ToolPart.
      /// </summary>
      ///<returns>An array of references to ToolPart objects.</returns>
    //  public override ToolPart[] GetToolParts()
    //  {
    //   ToolPart[] toolparts = new ToolPart[2];
    //   WebPartToolPart wptp = new WebPartToolPart();
    //   CustomPropertyToolPart custom = new CustomPropertyToolPart();
    //   toolparts[0] = wptp;
    //   toolparts[1] = custom;
    //   return toolparts;
    //  }
      
      /// <summary>
      /// Render this Web Part to the output parameter specified.
      /// </summary>
      /// <param name="output"> The HTML writer to write out to </param>
      ///
      protected override void CreateChildControls()
      {
       base.CreateChildControls ();
       SPWeb web = SPControl.GetContextWeb(this.Context);

       listList = new DropDownList();
       listList.EnableViewState = false;
       listList.Width = new Unit("100%");
       listList.AutoPostBack = true;

       foreach(SPList lst in web.Lists)
       {
        ListItem li = new ListItem(lst.Title, lst.ID.ToString());
        listList.Items.Add(li);
       }

       listList.SelectedIndexChanged += new EventHandler(list_SelectedIndexChanged);
       this.Controls.Add(listList);

       ///所有提醒人員列表
       alertList = new ListBox();
       alertList.EnableViewState = false;
       alertList.Width = new Unit("100%");
       alertList.Height = 200;

       this.Controls.Add(alertList);

       userList = new DropDownList();
       userList.EnableViewState = false;
       userList.Width = new Unit("100%");

       foreach(SPUser user in web.SiteUsers)
       {
        userList.Items.Add(new ListItem(user.Name, user.LoginName));
       }
       
       this.Controls.Add(userList);

       ///增加[提醒]對象
       addAlert = new LinkButton();
       addAlert.Text = "新增[Alerts]對象";
       addAlert.Click +=new EventHandler(addAlert_Click);
       
       this.Controls.Add(addAlert);

       ///所有人員均為[提醒]對象
       addAllAlerts = new LinkButton();
       addAllAlerts.Text = "新增[所有]對象";
       addAllAlerts.Click += new EventHandler(addAllAlerts_Click);

       this.Controls.Add(addAllAlerts);

       ///針對[一有變更]. [增加Items]. [變更Items]. [刪除Items]送出提醒
       alertTypeAll = new RadioButton();
       alertTypeAll.Text = "[所有變更]";
       alertTypeAll.AutoPostBack = false;
       alertTypeAll.Checked = true;

       this.Controls.Add(alertTypeAll);

       alertTypeAdded = new RadioButton();
       alertTypeAdded.Text = "[增加Items]";
       alertTypeAdded.AutoPostBack = false;
       
       this.Controls.Add(alertTypeAdded);
       
       alertTypeChanged = new RadioButton();
       alertTypeChanged.Text = "[變更Items]";
       alertTypeChanged.AutoPostBack = false;
       
       this.Controls.Add(alertTypeChanged);
       
       alertTypeDeleted = new RadioButton();
       alertTypeDeleted.Text = "[刪除Items]";
       alertTypeDeleted.AutoPostBack = false;
       
       this.Controls.Add(alertTypeDeleted);
       
       alertTypeAll.GroupName = "AlertType";
       alertTypeAdded.GroupName = "AlertType";
       alertTypeChanged.GroupName = "AlertType";
       alertTypeDeleted.GroupName = "AlertType";

      }

      private void list_SelectedIndexChanged(object sender, EventArgs e)
      {
       DisplaySelectedList();
      }

      private void DisplaySelectedList()
      {
       alertList.Items.Clear();

       SPWeb web = SPControl.GetContextWeb(this.Context);
       SPList selectedList = web.Lists[new System.Guid(listList.SelectedItem.Value)];

       foreach(SPAlert alert in web.Alerts)
       {
        if(alert.List.ID == selectedList.ID)
        {
         AddAlertToList(alert);
        }
       }
      }

      private void addAlert_Click(object sender, EventArgs e)
      {
       try
       {
        SPWeb web = SPControl.GetContextWeb(this.Context);

        SPList selectedList = web.Lists[new System.Guid(listList.SelectedItem.Value)];
        
        SPUser selectedUser = web.SiteUsers[userList.SelectedItem.Value];

        System.Guid newAlertGuid = selectedUser.Alerts.Add(selectedList, GetSelectedChangeType(), GetSelectedFrequency());
        AddAlertToList(selectedUser.Alerts[newAlertGuid]);
       }
       catch(Exception ex)
       {
        Console.WriteLine(ex.Message.ToString());
       }
      }

      private void addAllAlerts_Click(object sender, EventArgs e)
      {
       SPWeb web = SPControl.GetContextWeb(this.Context);

       SPList selectedList = web.Lists[new System.Guid(listList.SelectedItem.Value)];

       foreach(SPUser user in web.SiteUsers)
       {
        System.Guid newAlertGuid = user.Alerts.Add(selectedList, GetSelectedChangeType(), GetSelectedFrequency());
        AddAlertToList(user.Alerts[newAlertGuid]);
       }
      }

      private SPEventType GetSelectedChangeType()
      {
       SPEventType changeType = SPEventType.All;

       if(alertTypeAll.Checked)
        changeType = SPEventType.All;
       else if(alertTypeAdded.Checked)
        changeType = SPEventType.Add;
       else if(alertTypeChanged.Checked)
        changeType = SPEventType.Modify;
       else if(alertTypeDeleted.Checked)
        changeType = SPEventType.Delete;

       return changeType;
      }

      private SPAlertFrequency GetSelectedFrequency()
      {
       SPAlertFrequency frequencyType = SPAlertFrequency.Immediate;

       return frequencyType;
      }

      private void AddAlertToList(SPAlert alert)
      {
       string itemText = string.Format("{0} - {1}/{2}", alert.User.Name, alert.AlertFrequency.ToString(), alert.EventType.ToString());
       alertList.Items.Add(new ListItem(itemText, alert.ID.ToString()));
      }

      protected override void RenderWebPart(HtmlTextWriter output)
      {
    //   output.Write(SPEncode.HtmlEncode(Text));
       SPWeb web = SPControl.GetContextWeb(this.Context);
       if(!web.CurrentUser.IsSiteAdmin)
       {
        output.Write("<b>你不具有系統管理人員權限</b>");
       }
       
       output.WriteLine("<table width='100%'>");
       output.WriteLine("<tr>");
       output.WriteLine("<td>");
       listList.RenderControl(output);
       output.WriteLine("</td>");
       output.WriteLine("</tr>");

       output.WriteLine("<tr>");
       output.WriteLine("<td>");
       alertList.RenderControl(output);
       output.WriteLine("<br>");
       output.WriteLine("</td>");
       output.WriteLine("</tr>");
       
       output.WriteLine("<tr>");
       output.WriteLine("<td>");
       output.WriteLine("&nbsp;");
       output.WriteLine("</td>");
       output.WriteLine("</tr>");
       output.Write("<br>");
       
       output.WriteLine("<tr>");
       output.WriteLine("<td>");
       userList.RenderControl(output);
       output.Write("<br>");
       output.Write("●");
       addAlert.RenderControl(output);
       output.Write("<br>");
       output.Write("●");
       addAllAlerts.RenderControl(output);
       output.WriteLine("</td>");
       output.WriteLine("</tr>");

       output.WriteLine("<tr>");
       output.WriteLine("<td>");
       output.Write("<br>");
       output.WriteLine("<b>設定何時通知</b><br>");
       
       output.WriteLine("<table width='100%'>");
       output.WriteLine("<tr valign=top>");
       output.WriteLine("<td>");

       alertTypeAll.RenderControl(output);

       alertTypeAdded.RenderControl(output);

       alertTypeChanged.RenderControl(output);

       alertTypeDeleted.RenderControl(output);
       output.WriteLine("</td>");
       output.WriteLine("<td>");

       output.WriteLine("</table>");
       output.WriteLine("</td>");
       output.WriteLine("</tr>");
       
       output.WriteLine("</table>");
      }
     }
    }

    2006年12月14日 下午 02:32
  • 試試看... 這是幫所有人設定 Alert 的一之網頁組件
    2006年12月14日 下午 02:33