В Elements.xml указываем конкретный список
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Receivers ListUrl="/request/proxy/Lists/Proxy"> //ВОТ ТУТ
<Receiver>
<Name>ProxyERItemAdded</Name>
<Type>ItemAdded</Type>
<Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
<Class>PAC.Proxy.ProxyER.ProxyER</Class>
<SequenceNumber>10000</SequenceNumber>
</Receiver>
<Receiver>
<Name>ProxyERItemUpdated</Name>
<Type>ItemUpdated</Type>
<Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
<Class>PAC.Proxy.ProxyER.ProxyER</Class>
<SequenceNumber>10000</SequenceNumber>
</Receiver>
</Receivers>
</Elements>
В Feature1 оставляем Web части, область Site, в Feature2 только EventReciever, область Web
Шаблон:
/// <summary>
/// Добавлен элемент.
/// </summary>
public override void ItemAdded(SPItemEventProperties properties)
{
base.ItemAdded(properties);
Execute(properties);
}
/// <summary>
/// Обновлен элемент.
/// </summary>
public override void ItemUpdated(SPItemEventProperties properties)
{
base.ItemUpdated(properties);
Execute(properties);
}
/// <summary>
/// Выполнение
/// </summary>
/// <param name="properties"></param>
void Execute(SPItemEventProperties properties)
{
try
{
}
catch (Exception e)
{
SendError(properties.ListItem, e.Message);
throw;
}
}
/// <summary>
/// Отправляем письмо
/// </summary>
/// <param name="to"></param>
/// <param name="subject"></param>
/// <param name="body"></param>
private void SendMessage(string to, string subject, string body)
{
SmtpClient sc = new SmtpClient("casarray.pac.local");
MailMessage msg = new MailMessage();
msg.IsBodyHtml = true;
msg.From = new MailAddress("sharepoint@pac.ru");
msg.To.Add(to);
//msg.To.Add("v.fedunov@pac.ru");
//msg.Bcc.Add("v.fedunov@pac.ru");
//msg.Bcc.Add("e.gelvig@pac.ru");
//msg.Bcc.Add("sharepoint@pac.ru");
msg.Subject = subject;
//msg.Body = to + "<br/>";
msg.Body = body;
//Отправляем
sc.Send(msg);
}
/// <summary>
/// Отправляем письмо с ошибкой
/// </summary>
/// <param name="to"></param>
/// <param name="subject"></param>
/// <param name="body"></param>
private void SendErrorMessage(string to, string subject, string body)
{
SmtpClient sc = new SmtpClient("casarray.pac.local");
MailMessage msg = new MailMessage();
msg.IsBodyHtml = true;
msg.From = new MailAddress("sharepoint@pac.ru");
msg.To.Add(to);
msg.Subject = subject;
msg.Body = body;
//Отправляем
sc.Send(msg);
}
/// <summary>
/// Обновление элемента
/// </summary>
/// <param name="item"></param>
void DoUpdate(SPListItem item)
{
SPItemEventReceiverHandling rh = new SPItemEventReceiverHandling();
rh.DisableEventFiring();
//Статус выполнения ER
item["EventStatus"] = "Завершен";
//Обновляем
item.Update();
rh.EnableEventFiring();
}
/// <summary>
/// Системное обновление элемента
/// </summary>
/// <param name="item"></param>
void DoSystemUpdate(SPListItem item)
{
SPItemEventReceiverHandling rh = new SPItemEventReceiverHandling();
rh.DisableEventFiring();
//Статус выполнения ER
item["EventStatus"] = "Завершен";
//Обновляем
item.SystemUpdate();
rh.EnableEventFiring();
}
/// <summary>
/// Смена статуса
/// </summary>
/// <param name="status"></param>
/// <param name="itm"></param>
void SetStatus(string status, SPListItem itm)
{
SPItemEventReceiverHandling rh = new SPItemEventReceiverHandling();
itm["EventStatus"] = status;
rh.DisableEventFiring();
itm.Update();
rh.EnableEventFiring();
}
// <summary>
/// Отправка ошибки
/// </summary>
/// <param name="itm"></param>
/// <param name="error"></param>
void SendError(SPListItem itm, string error)
{
SetStatus("Ошибка", itm);
SendErrorMessage("v.fedunov@pac.ru", "Event error", "List: " + itm.Web.Site.Url + itm.ParentList.DefaultDisplayFormUrl + "?ID=" + itm.ID + "<br/>" + error);
}
private class SPItemEventReceiverHandling : SPItemEventReceiver
{
public SPItemEventReceiverHandling()
{
}
new public void DisableEventFiring()
{
base.EventFiringEnabled = false;
}
new public void EnableEventFiring()
{
base.EventFiringEnabled = true;
}
}