Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I need to change the displayname of a list using "ItemUpdating". The source of the new name is the "Title"-field of the item which fires the event. Is this possible? I tried it with:

if ((properties.ListTitle == "Fahrzeuge") || (properties.ListTitle == "Räume"))
            {
                base.ItemUpdating(properties);

                try
                {
                    base.DisableEventFiring();

                    string origCalTitle = properties.ListItem["Title"].ToString();
                    string newCalTitle = properties.AfterProperties["Title"].ToString();

                    if (origCalTitle != newCalTitle)
                    {
                        using (SPWeb web = properties.OpenWeb())
                        {
                            CultureInfo origCulture = Thread.CurrentThread.CurrentUICulture;

                            web.AllowUnsafeUpdates = true;

                            SPList changeList = web.Lists[origCalTitle];

                            Thread.CurrentThread.CurrentUICulture = new CultureInfo((int)web.Language);

                            changeList.Title = newCalTitle;
                            changeList.Update();

                            web.AllowUnsafeUpdates = false;
                        }
                    }
                }
                finally
                {
                    base.EnableEventFiring();
                }
            }

I also tried it on some other way, like ItemUpdating and Afterproperties but nothing happens. Unfortunately I am not a pro in programming Event Receiver und also Google doesn´t help me out, so I need help.

Thanks for all effort!

share|improve this question

2 Answers 2

public override void ItemUpdating(SPItemEventProperties properties)
    {
        SPSecurity.RunWithElevatedPrivileges(delegate()
        {
            if ((properties.ListTitle == "Fahrzeuge") || (properties.ListTitle == "Räume"))
            {

            string currentTitle = properties.ListItem["Title"].ToString();
            string newTitle = properties.AfterProperties["Title"].ToString();

            if (currentTitle != newTitle)
            {
                properties.AfterProperties["Title"] = calTitle;
            }

        }
    });
}
share|improve this answer

Add the code in the ItemUpdated.

I have gone through your code, sorry i missed that your elevating user lol, i can see that your using the properties object. As your using that its only read only. You have two things you can do here:

1) create the spsite and spweb object to update the list

or

2) use the itembefore and after to change the title

ItemUpdating not saving field values

    string calTitle = properties.ListItem["Title"].ToString();

    using (SPSite site = new SPSite(properties.WebUrl))
    using (SpWeb web = site.OpenWeb())
    {
       web.AllowUnsafeUpdates = true;

       SPList changelist = web.Lists[calTitle];

       changelist.Title = calTitle;
       changelist.Description = calTitle;

       changelist.Update();
       web.AllowUnsafeUpdates = false;
    }

or

if i got this right the properties should look somthing like this:

    public override void ItemUpdated(SPItemEventProperties properties)
    {
        SPSecurity.RunWithElevatedPrivileges(delegate()
        {
            if ((properties.ListTitle == "Fahrzeuge") || (properties.ListTitle == "Räume"))
            {

                string currentTitle = properties.ListItem["Title"].ToString();
                string newTitle = properties.AfterProperties["Title"].ToString();

                if (currentTitle != newTitle)
                {
                    properties.AfterProperties["Title"] = calTitle;
                }

            }
        });
    }

http://stackoverflow.com/questions/14994981/how-to-update-one-list-from-another-using-itemupdated-event-receiver-in-sharepoi

http://www.synergyonline.com/Blog/Lists/Posts/Post.aspx?ID=122

share|improve this answer
    
Sorry, but both ways wont work for me :-/ –  Felix Zeidler Mar 21 '13 at 10:09
    
just ammended my answer by using changelist.SystemUpdate(false); –  ali Sharepoint Mar 21 '13 at 10:34
    
I updated my first post with alle my code for ItemUpdated. Isn´t it the same way as you suggest except of cahangelist.SystemUpdate(false)? –  Felix Zeidler Mar 21 '13 at 13:04
    
One more thing... I´m doing this for SP2007. Because of this I use base.DisableEventFiring(); –  Felix Zeidler Mar 21 '13 at 13:14
    
are you getting any errors in eventviewer? does the account have privlages to make changes –  ali Sharepoint Mar 21 '13 at 13:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.