A Practical Guide to SharePoint 2013

A Practical Guide to SharePoint 2013
A Practical Guide to SharePoint 2013 - Book by Saifullah Shafiq

Friday, September 24, 2010

spListItem["Modified By"] property gives you the name of the person who last modified the document.
Have a look at the following code. You can get file's URL in EventFileURL if you are using EventHandlerToolkit.
spFile = EventWeb.GetFile( EventFileUrl );
if (spFile.Exists)
{
spListItem = spFile.Item;
}
string strModifiedBy = spListItem["Modified By"].ToString();
and if you want to send an email, here is how you can do it. You can send email in OnDelete(), OnInsert(), OnUpdate(), etc
private void OnDelete()
{
    //Insert code here: capture the name of the person who modified the document
    //Send email

MailMessage msg;
  
SmtpMail.SmtpServer = "smtp.yourserver.com";
msg = new MailMessage();
msg.BodyFormat = MailFormat.Html;
msg.From =  currentWeb.Author.Email; //you can use hard code the sender here
msg.Subject = "File Deleted";
msg.Body = "File has been deleted";
msg.To = currentWeb.Users[strModifiedBy].Email;
SmtpMail.Send(msg);
    
}

-SSA

No comments:

Post a Comment