I have a sp 2010 cutom list. Whenever the list gets updated, an email should be sent to some specific people and body of the email should be taken from "messageList" I searched net, most of the solutions suggests workflow. i dont want to use that since the solution has to deployed to many enviornments.
How to do it.
Below is my event for item added.
Public override void ItemAdded(SPItemEventProperties properties)
{
base.ItemAdded(properties);
try
{
if (string.Equals(properties.ListTitle, DocLibTitle, StringComparison.OrdinalIgnoreCase))
{
//string line = string.Empty;
SPWeb web = properties.Web;
if (properties.AfterUrl.EndsWith(".csv", StringComparison.OrdinalIgnoreCase))
{
SPFile file = web.GetFile(properties.AfterUrl);
if (file.Exists)
{
SPList calendarList = web.Lists.TryGetList(CalendarListTitle);
SPList messageList = web.Lists.TryGetList(MessageListTitle);
if (calendarList != null)
{
StreamReader content;
content = new StreamReader(file.OpenBinaryStream());
var data = Parse(content);
foreach (var fieldValues in data)
{
SPListItem item = calendarList.Items.Add();
item["ChangeOrderNumber"] = fieldValues[0];
item["Requestor"] = fieldValues[1];
item["ImplementationStartDate"] = fieldValues[2];
item["ImplementationEndDate"] = fieldValues[3];
item["COStatus"] = fieldValues[4];
item["Assignee"] = fieldValues[5];
item["OrderSummary"] = fieldValues[6];
item["OrderDescription"] = fieldValues[7];
item["Justification"] = fieldValues[8];
item["COURL"] = fieldValues[9];
item.Update();
SPListItem messageItem = messageList.Items.Add();
messageItem["SendEmailTo"] = item["Requestor"];
messageItem["SendEmailCC"] = item["Requestor"];
messageItem["EmailBody"] = item["OrderSummary"];
messageItem.Update();
}
}
}
}
}
}
0 commentaires:
Enregistrer un commentaire