locked
ItemAttachmentAdded Event Handler RRS feed

  • Question

  • 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.
    Thursday, May 31, 2012 7:00 AM

Answers

  • 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

    Friday, June 1, 2012 9:26 AM
    Moderator