Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • mots 44 posts 75 karma points
    Dec 20, 2010 @ 16:02
    mots
    0

    Getting the new value to save on action

    Hi,

    I am using the BeforeSave action handler to run some code before a document is saved (and then published). What I would like to do is get the new value the user has entered in the field, format it, and then save it as normal.

    However when I try to save the document I cant seem to find a way to get the new value the user has entered for that field rather than its existing value. Currently I am only able to get the existing value and not the new one.

    Here is my code in a method:

    private void Document_BeforeSave(Document sender, SaveEventArgs e)
    {
        if (sender.getProperty("umbracoUrlAlias") != null &&
            !string.IsNullOrEmpty(sender.getProperty("umbracoUrlAlias").Value.ToString()))
        {
            string alternateUrl = sender.getProperty("umbracoUrlAlias").Value.ToString().ToLower().TrimStart('/').TrimEnd('/') + "/";
            sender.getProperty("umbracoUrlAlias").Value = alternateUrl;
            sender.Publish(sender.User);
        }
    }

    I understand I am getting the value in the property from the document's property collection, and obviously it will have the existing value in there. But how can I get the new value the user has entered?

    Thanks.

  • mots 44 posts 75 karma points
    Dec 20, 2010 @ 16:48
    mots
    0

    Just thought of the solution to this. Rather than do it on BeforeSave, I am now doing it in AfterSave, which works perfectly now.

Please Sign in or register to post replies

Write your reply to:

Draft