Copied to clipboard

Flag this post as spam?

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


  • Nik Wahlberg 639 posts 1237 karma points MVP
    Aug 23, 2009 @ 21:59
    Nik Wahlberg
    0

    Checking if proprty is null OR empty

    Hi, am attaching to the BeforePublsh to set a property value of a document type. It works fine, but now I want to check if the user has entered a value before attempting to set it programatically. Here' what I have:

    //Always LOG
    Log.Add(LogTypes.Custom, sender.Id, "Attempting to set the expiration date of CLASSIFIED AD: " + sender.Text);

    if (sender.ContentType.Alias == "ClassifiedAd")
    {
        DateTime dt = DateTime.Now;
        if (sender.getProperty("adExpirationDate").Value == null) sender.getProperty("adExpirationDate").Value = dt.AddDays(21);
    }

    Log.Add(LogTypes.Custom, sender.Id, "Expiration set successfully: " + sender.Text);

    When the date has been left blank, the Value is not null. How can I check if it is empty?

    Thanks,
    Nik

  • Chris Koiak 700 posts 2626 karma points
    Aug 23, 2009 @ 22:08
    Chris Koiak
    100
    if (sender.getProperty("adExpirationDate").Value == null || sender.getProperty("adExpirationDate").ToString().Length == 0)
    {
    sender
    .getProperty("adExpirationDate").Value = dt.AddDays(21);
    }

    Does that work??

  • Nik Wahlberg 639 posts 1237 karma points MVP
    Aug 23, 2009 @ 22:17
    Nik Wahlberg
    0

    Awesome, should have thought of that. Thanks!

  • Fengelz 106 posts 221 karma points
    Aug 28, 2009 @ 14:38
    Fengelz
    0

    You could possibly also do this (just to shorten it down a bit): 

    if (String.IsNullOrEmpty(sender.getProperty("adExpirationDate").Value)
    {
         sender
    .getProperty("adExpirationDate").Value = dt.AddDays(21);
    }

Please Sign in or register to post replies

Write your reply to:

Draft