none
event receiver itemAdded problem RRS feed

  • Question

  • i have two environments: test and production environment. i created even receiver that set name of document on 'Некласификовано-iddocument.extension' - 'Име' field and the receiver set name of document before upload in 'Наслов' field' after uploading. this receiver works ok in test environment, but in production environment after i click upload my 'Наслов' field receive value from 'Име' field after upload. my code is

     public override void ItemAdded(SPItemEventProperties properties)
            {
    
                this.EventFiringEnabled = false;
                SPFile f = properties.ListItem.File;
                string spfileExt = new FileInfo(f.Name).Extension;
                 if (properties.ListItem == null)
                    {
                        throw new ArgumentNullException("listItem");
                    }
                    string naslov = properties.ListItem.DisplayName;
                    properties.ListItem["Наслов"] = naslov;
                    properties.ListItem["Некласификовано"] = "Некласификовано";
                    properties.ListItem["Име"] = "Некласификовано-" + properties.ListItemId + spfileExt;
                    properties.ListItem.SystemUpdate();
    
                
    
                base.ItemAdded(properties);
                this.EventFiringEnabled = true;
    
            }

    picture from test

    picture from production

    Friday, August 2, 2019 10:22 AM

All replies

  • i tryed with

    string spfileName = new FileInfo(f.Name).Name;
    properties.ListItem["Наслов"] = spfileName;
    

    instead

    string naslov = properties.ListItem.File.Name;
    properties.ListItem["Наслов"] = naslov;

    but again, the situatiion is same. in test the code works,but in production does not works

    what i do?

    Friday, August 2, 2019 12:05 PM
  • i tryed with next code

     public override void ItemAdding(SPItemEventProperties properties)
            {
                base.ItemAdding(properties);
                string currTitle = properties.AfterProperties["vti_title"] as string;
                string url = properties.AfterUrl;
                var name = url.Substring(url.LastIndexOf('/') + 1);
                //NOTE! Name is only copied to Title if title is not set. Will not handle name changes!
                if (string.IsNullOrEmpty(currTitle))
                {
                    properties.AfterProperties["vti_title"] = name;
                }
            }
    

    again the situation is the same. test works, the product not

    now, in product environment 'Наслов' field is empty

    Friday, August 2, 2019 1:09 PM
  • Hi,

    I did sample test in my local environment, the Title and Name will be updated correctly.

    Is any other logic(event receiver/workflow) in your production environment?

    https://nikcharlebois.com/retrieving-a-list-of-event-receivers-using-powershell/

    Test demo:

    public override void ItemAdded(SPItemEventProperties properties)
            {
                this.EventFiringEnabled = false;
                base.ItemAdded(properties);
                SPFile f = properties.ListItem.File;
                string spfileExt = new FileInfo(f.Name).Extension;
                if (properties.ListItem == null)
                {
                    throw new ArgumentNullException("listItem");
                }
                string naslov = properties.ListItem.DisplayName;
                properties.ListItem["Title"] = naslov;            
                properties.ListItem["Name"] = "prefix-" + properties.ListItemId + spfileExt;
                properties.ListItem.SystemUpdate(false);            
                this.EventFiringEnabled = true;
            }


    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Monday, August 5, 2019 1:55 AM
  • i resolve my problem with next code

    public override void ItemAdding(SPItemEventProperties properties)
            {
                base.ItemAdding(properties);
                string currTitle = properties.AfterProperties["vti_title"] as string;
                string url = properties.AfterUrl;
                var name = url.Substring(url.LastIndexOf('/') + 1);
                //NOTE! Name is only copied to Title if title is not set. Will not handle name changes!
                if (string.IsNullOrEmpty(currTitle))
                {
                    properties.AfterProperties["vti_title"] = name;
                }
            }

    Monday, August 5, 2019 8:32 AM
  • Hi,

    Thank you for your feedback.

    You can mark your solution as answer so it would help other community members find the helpful information quickly.

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Monday, August 5, 2019 8:35 AM