Copied to clipboard

Flag this post as spam?

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


  • Vasilis 8 posts 118 karma points
    Dec 19, 2017 @ 20:42
    Vasilis
    0

    Is it possible to use obsolete umbraco picker properties in umbraco 7.6.3

    Hello,

    I have updated a site from version 4.7.2 to 7.6.3 but now I have realized I have bumped into a big problem - or so I think. The site is supposed to work with the old code plus some tweaks. The problem is that I have not noticed that in 7.6.3 and after comes the new umbraco picker properties that use the umb/content/guid structure. However I would like to keep the obsolete properties that work like 1234,1235,4324 - it seems they work fine with the existing structure. But I have failed to update some properties, because I missed them or because I was planning to do some extra work and now I can't use the old obsolete properties.

    I am really at loss how to handle this. It is really important for me to use the properties like 1234,1235,4324. It seems that dynamic pages works fine like that - or so it seems to me. Any help would be really appreciated. The updated happened before summer and I am not sure I can fallback to a previous state. I was also thinking of downgrading umbraco.

  • Sven Geusens 169 posts 881 karma points c-trib
    Dec 20, 2017 @ 10:31
    Sven Geusens
    0

    Hey Vasilis, could you show the code that is failing?

  • Sebastiaan Janssen 5045 posts 15478 karma points MVP admin hq
    Dec 20, 2017 @ 11:07
    Sebastiaan Janssen
    0

    You can update your templates and handle the new values (we call them UDI, Umbraco Identifiers).

    Here's some code that can pretty safely convert UDI's back to a numeric id:

    @{
        var listOfValues = new List<string>();
        listOfValues.Add("umb://document/4fed18d8c5e34d5e88cfff3a5b457bf2");
        listOfValues.Add("1233");
        foreach(var val in listOfValues) 
        {
            int id;
    
            // try to see if the id is a number, if it is not, try to parse
            // it as a UDI and then get the integer Id from it
            if(int.TryParse(val, out id) == false)
            {
                try
                {
                    Udi udi = new GuidUdi(new Uri(val));
                    id = Umbraco.GetIdForUdi(udi);
                }
                catch (System.FormatException) 
                {
                    // this doesn't seem to be a Udi either
                    // do something to handle the error
                }
            }
    
            <h2>Id is @id</h2>
        }
    }
    

    Remember, this is just an example, I am assuming you already have a list of values, so this is just there to test that the code works.

    If Umbraco.GetIdForUdi(udi) doesn't work for you, you might have to get an umbracoHelper instead, so that code changes to:

    var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
    Udi udi = new GuidUdi(new Uri(val));
    id = umbracoHelper.GetIdForUdi(udi);
    

    However, I can't remember exactly how this would work in dynamic razor, you might need to construct the umbracoHelper like this: var umbracoHelper = new Umbraco.Web.UmbracoHelper(Umbraco.Web.UmbracoContext.Current);

  • Vasilis 8 posts 118 karma points
    Dec 20, 2017 @ 11:53
    Vasilis
    100

    Thanks! Well I read again the version specific upgrade guide and I have found that I can use obsolete media pickers by adding the

    <showDeprecatedPropertyEditors>true</showDeprecatedPropertyEditors>
    

    in the umbracoSettings.config file, so I can choose them instead. I also had a backup of the database from the previous day so now it seems that everything works ok. Thanks a lot for the code it might come handy after all!!!

  • Sebastiaan Janssen 5045 posts 15478 karma points MVP admin hq
    Dec 20, 2017 @ 14:39
    Sebastiaan Janssen
    0

    No problem. You did say the update was done before the summer so I figured you couldn't go back.

    Good luck in any case!

Please Sign in or register to post replies

Write your reply to:

Draft