Check if string is null

The problem is that you’re trying to use a variable that is declared inside a block with a narrower scope (you define crPhoto1Data inside the if block). Another problem is that you’re trying to set it to more than one type.

One way solve this is to create the JObject in an if/else statement (or using the ternary operator as in my sample below):

JObject ph1json = string.IsNullOrEmpty(crphoto1)
    ? new JObject
        {"ContactID", crcontactID},
        {"Photo1", ""}
    : new JObject
        {"ContactID", crcontactID},
        {"Photo1", File.ReadAllBytes(crphoto1)}

Leave a Comment