Hello Michuk,
In a document library, there is no attachment. We upload documents. Code for document library and list could be different because list can have more than one attachment.
You can create an event receiver to split the attachment name and update the columns you want. You can put your code in ItemAdded method. It will run after you press save button.
Here is a sample code for your reference, it is using Server Object Model. It will update FileName column to attachment file name. You need to modify it if you have more than 1 attachment.
public
override
void ItemAdded(SPItemEventProperties
properties)
{
SPListItem lstItem = properties.ListItem;
string listAttachmentName
= lstItem.Attachments[0]; // get first attachment name for list
string[] listAttachemtNameSplit
= listAttachmentName.Split('_');
//split the attachment name for list
lstItem["FileName"]
= listAttachemtNameSplit[0]; //first item in array is attachment file name
lstItem.Update();
}
Here are some information about event receivers:
https://msdn.microsoft.com/en-us/library/office/gg252010(v=office.14).aspx
https://msdn.microsoft.com/en-us/library/office/gg749858(v=office.14).aspx
Thank you
-
Edited by
ali tun
1 hour 45 minutes ago