Copied to clipboard

Flag this post as spam?

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


  • Phil Crowe 192 posts 256 karma points
    Nov 29, 2010 @ 12:53
    Phil Crowe
    0

    upload property not returning null

    if ((color.GetProperty("alternateColourImage").Value != null) || (color.GetProperty("alternateColourImage").Value != String.Empty))

    {
     Response.Write("col:" + color.GetProperty("alternateColourImage").Value +  "end");

    }

     

     

    For some reason this logic is working for every node i want it to work on apart from 2. 'alternateColourImage' is an 'upload' property, if it there is no image uploaded to the node i dont want the browser to write anything. but for some reason its writing this for two of my nodes  'col:end' so obviuosly there is no value assigned to the property but its still writing this text out! any ideas?

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Nov 29, 2010 @ 14:58
    Lee Kelleher
    0

    Hi Phil,

    I think it's to do with the logic of your condition.  If the value is not null OR not String.Empty ... but if it was null, then that would make the " != String.Empty" to be true... right? Which would display the condition.

    I'd suggest that you assign the GetProperty() to a variable, saves recalling the method (not sure if it gets cached, or hits the database each time?) ... to something like this:

    var altColourImage = color.GetProperty("alternateColourImage");
    if (altColourImage != null && altColourImage.Value != null && !string.IsNullOrEmpty(altColourImage.Value.ToString()))
    {
        Response.Write("col:" + altColourImage.Value.ToString() + "end");
    }

    With the condition, you'll need to check that the Property itself is not null, then if the Value is not null, then finally that the Value (as a String) is not null/empty. Seems a bit long winded, but its better to be safe, right?

    Cheers, Lee.

Please Sign in or register to post replies

Write your reply to:

Draft