ItemAttachmentAdded Event Handler
Hi, I try to handle ItemAttachmentAdded event. I want to change the name of the attached file. After searching, I understood that I cant change the name of the file. A developer told that we could copy the content of the file and create a new file with the same content and also in this way we could give the any name we want. I'm accessing the attachments of the related list item by listItemName.Attachments. Since I cant find the name of the lastly attached file (This is my problem), I'm not able to change the file lastly attached. What I want to know is which file triggered the ItemAttachmentAdded event and what this files name is. Thanks.
May 31st, 2012 3:05am

Hi bllcybrztrk, You can get your last attachment file name by the following code. public override void ItemAdded(SPItemEventProperties properties) { SPListItem item= properties.ListItem; SPAttachmentCollection attach = item.Attachments; for (int i = 0; i < item.Attachments.Count; i++) { if (i == item.Attachments.Count - 1) { string name = attach[i];// this is your last attachment name } } } Thanks, Jack
Free Windows Admin Tool Kit Click here and download it now
June 1st, 2012 5:26am

Hi bllcybrztrk, You can get your last attachment file name by the following code. public override void ItemAdded(SPItemEventProperties properties) { SPListItem item= properties.ListItem; SPAttachmentCollection attach = item.Attachments; for (int i = 0; i < item.Attachments.Count; i++) { if (i == item.Attachments.Count - 1) { string name = attach[i];// this is your last attachment name } } } Thanks, Jack
June 1st, 2012 5:27am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics