Sharepoint 2010 email event receiver - sharepoint

I am creating an email event receiver for sharepoint 2010 for a document library that receives emails in and I want to be able to then copy those emails that are sent to that list to another one. Now how would I go about doing that using an email event receiver rather than a itemAdded event receiver? what object methods can I use to get a copy method to another list etc?

SPEmailEventReceiver has the EMailReceived method.
When you take the MSDN example code:
public class Email_Handler: SPEmailEventReceiver
{
public override void EmailReceived(
SPList oList,
SPEmailMessage oMessage,
string strReceiverData)
{
SPListItem oListItem = oList.Items.Add();
oListItem["Title"] = oMessage.Headers["Subject"];
oListItem["Body"] = oMessage.HtmlBody;
oListItem.Update();
}
}
You see that they add the list item to the list via oList.Items.Add() which is exactly what you can do. You could also add the item to any other list.
Once you have the list item you could copy it to any other list by using the SPListItem.CopyTo method.
A good example for an EMail event receiver: http://pholpar.wordpress.com/2010/01/13/creating-a-simple-email-receiver-for-a-document-library/

Related

Kentico 13 - How to add BCC to the marketing email?

I want to add BCC to the marketing email. Is there any way to do that?
I tried using the below code. But it did not work.
public override void Init()
{
EmailInfo.TYPEINFO.Events.Insert.Before += Email_Insert_Before;
}
private void Email_Insert_Before(object sender, ObjectEventArgs e)
{
var email = e.Object as EmailInfo;
email.EmailBcc = "admin#company.com";
EmailInfo.Provider.Set(email);
}
The Insert Before event is probably not the one you are looking for to customize marketing automation processes / steps. It would be easier to implement a custom Action (Marketing Automation -> Actions -> New) and tie the Action configuration to the a custom C# class. Once you have a new action, you can add Parameters to it. You could add a Parameter to let the admin configure the Email BCC.
Documentation on how to do that is here: https://docs.xperience.io/on-line-marketing-features/configuring-and-customizing-your-on-line-marketing-features/configuring-marketing-automation/developing-custom-marketing-automation-actions

How to access document attachments from hierarchical transformation

My site has this structure:
Products
category 1
item 1
item 1 attachments
category 2
item 2
item 2 attachments
I have successfully written a hierarchical transformation that shows the data on the page at the top level. I cannot for the life of me figure out how to access the attachments for each document though.
Anyone have any idea?
If you are talking about Group attachments (this is when you have a field in your page type using the Attachments data type) then in order to access the attachments inside your transformation you need to write either a custom macro (when using Text/XML transformation) or custom transformation method. Both can be done very easily. The code itself that gets you the attachments can be like this:
public ObjectQuery<AttachmentInfo> GetAttachmentsFromField(string className, int documentID, string attachmentColumnName)
{
// get class info
var classInfo = new FormInfo(DataClassInfoProvider.GetDataClassInfo(className).ClassFormDefinition);
if (classInfo != null)
{
// get attachment field definition
var attachmentsField = classInfo.GetFormField(attachmentColumnName);
if (attachmentsField != null)
{
// get attachments strored in the field by GUID
var attachments = AttachmentInfoProvider.GetAttachments()
.WhereEquals("3CCC6E6C-56F3-42EB-8385-979973D99C55", attachmentsField.Guid)
.And()
.WhereEquals("AttachmentDocumentID", documentID);
return attachments;
}
}
return null;
}
With this it is very important to take into account that this code introduces several other SQL queries against database and therefore it should be optimized by using caching appropriately.
I suppose you mean unsorted attachments you add in Properties -> Attachments section. In this case yuo can register following control in your transformation:
<%# Register Src="~/CMSInlineControls/DocumentAttachments.ascx" TagName="DocumentAttachments" TagPrefix="cms" %>
And use it like this:
<cms:DocumentAttachments ID="ucDocAttachments" runat="server" TransformationName="cms.root.attachment" Path='<%# Eval("NodeAliasPath") %>' />
I wrote a pretty detailed blog post on this a while back. It describes very similar attributes to Enn's answer but gives great detail on why you do specific things.

Appointment Send and Send Update

How can I know if for any appointment "Send" was clicked or " Send Update" or "Send Cancellation" was clicked.I have Application_ItemSend event which fires for both Send,Send Update and Send Cancellation. One way would be add a custom property and set some value when the appointment is initially created. But I don't seem to find a way to differentiate the button click. Is adding custom property the only way or is there any built in property which I can use. Appointment item I am assigning as below.
var appointment = Globals.MedearcOutlook2010AddIn.Application.ActiveInspector().CurrentItem as Outlook.AppointmentItem;
Thanks
You can check the MAPI property PR_MESSAGE_DELIVERY_TIME to see whether the appointment has been sent yet (isUpdate=false) or it is an update to an existing appointment (isUpdate=true). I didn't see a native property member for doing this.
string PR_MESSAGE_DELIVERY_TIME = "http://schemas.microsoft.com/mapi/proptag/0x0E060040";
bool isUpdate = false;
try
{
DateTime message_delivery = appointment.PropertyAccessor.GetProperty(PR_MESSAGE_DELIVERY_TIME);
isUpdate = true; // if it makes it here then the message has been delivered
}
catch { }

How do I create an event receiver for a single list that is based on a custom content type?

I am trying to create an event receiver for a list I have created called Questions.
When a new question is added I want an event to fire. I have looked into it so I know I need to create an event receiver and make use of the ItemAdded method.
How do I bind this to one instance of a list and what do I select for the Source type when creating the receiver? I don't have an option for "Custom List" in there as some blog posts suggest.
Hope someone can help..
I think this might be what you're after: (http://msdn.microsoft.com/en-us/library/ff407249.aspx)
using (SPSite site = new SPSite("http://localhost"))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists["Shared Documents"];
SPEventReceiverDefinition def = list.EventReceivers.Add();
def.Assembly = "ERDefinition, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=704f58d28567dc00";
def.Class = "ERDefinition.ItemEvents";
def.Name = "ItemAdded Event";
def.Type = SPEventReceiverType.ItemAdded;
def.SequenceNumber = 1000;
def.Synchronization = SPEventReceiverSynchronization.Synchronous;
def.Update();
}
}
Regards,
joel
--
http://joelblogs.co.uk
#joelblogs
If you don't want to do it using code, try the SP EventHandler Manager

Cannot update document property on ItemAdded event when using Vista

We are trying to create a custom event handler that would fire on ItemAdded event. The event handler then updates the document with a unique ID value to a column in this document library.
Our solution works fine, except when a user on Vista is trying to save a new document from Office 2007. In this scenario the document is stored to document library but Unique ID column is empty, and there is no exception.
Vista Users can upload document(s) to library without a problem. Everything else works fine on XP and Win2k3 operating systems.
Has anyone seen something similar, and what might be the problem here? To demonstrate the problem we are using DateTime.Now as unique ID.
using Microsoft.SharePoint;
public class TestReciever : SPItemEventReceiver
{
public override void ItemAdded(Microsoft.SharePoint.SPItemEventProperties properties)
{
try {
DisableEventFiring();
properties.ListItem("UniqueID Column") = DateTime.Now.ToString();
properties.ListItem.SystemUpdate();
EnableEventFiring();
}
catch (Exception ex) {
// handle exception
}
}
}
We have noticed exactly the same thing happening. When the 2007 doc is added to the library, the properties from the list are added to it (blank).
Then the (synchronous) event handler is called, updating the list with the correct values for the UniqueID column.
Then the inbuilt property mapping to 2007 docs kicks in and overwrites your values with those stored in the 2007 doc (not raising an item updated event again).
This means that the list now has a blank for your column.
If you change to an asynchronous event you may see what we did and that the slight delay for asynchronous meant that the property mapping to 2007 docs happened first (we think) meaning the value was stored correctly.
It is possible to break the property mapping between the list and office, but that is only a workaround.
I cannot for the life of me find where this info is on an MS site, but it is a known problem. Perhaps you can hang in there for SP2 (may even be fixed in SP1, but am unsure).
At the end we contacted Microsoft and they provided us with the following workaround solution. The key here is to delay item update in a separate thread.
private Guid listID;
private Guid itemID;
private Guid siteID;
public override void ItemAdded(Microsoft.SharePoint.SPItemEventProperties properties)
{
DisableEventFiring();
item = properties.ListItem;
listID = properties.ListId;
itemID = properties.ListItem.UniqueId;
siteID = properties.SiteId;
Threading.Thread setDocumentInternalIDThread = new Threading.Thread(SetInternalID);
setDocumentInternalIDThread.Start();
EnableEventFiring();
}
private void SetInternalID()
{
try {
Threading.Thread.Sleep(10000);
using (SPSite site = new SPSite(siteID)) {
using (SPWeb web = site.OpenWeb()) {
SPList list = web.Lists(listID);
SPListItem item = list.Items(itemID);
item(Common.CustomID) = Common.GetAlphaPrefix() + Common.GetDocNumber();
item.SystemUpdate();
}
}
}
catch (Exception ex) {
Log(ex.Message);
}
}
Another workaround is to set the custom field that is being updated in the event receiver to be read only (set the fields ReadOnly property to TRUE). This has a few pros and cons. This is ideal for a unique id solution, because there is no way for the user to modify the value. However, the field is hidden to the UI, so managing it becomes more troublesome, and the field can't be used in labels, or quick parts. You can set the ShowInDisplayForm property of the field to TRUE to have the field display in the view form, but not the edit form. The field can also be added to your views. This is the best workaround I have found for this issue to date.
This is an issue with Office 2007 and the WSS 3.0 xml parser. When the properties are promoted from the Office 2007 document, the parser attempts to assign document properties to the list properties in SharePoint (property promotion). The problem is that this event occurs after any ItemAdded, or ItemUpdated events, so the property gets overwritten with the value in the document, which is of course, blank. Microsoft has raised this as a bug, and I was hoping for a fix in SP2, but no such luck.

Resources