1

I want to check if the file inside my device exist. When the variable crphoto1 is empty or the file does not exist the "Photo1" json should be {"Photo1", ""}

JObject ph1json = string.IsNullOrEmpty(crphoto1)
? new JObject
{
    {"ContactID", crcontactID},
    {"Photo1", ""}
}
: new JObject
{
    {"ContactID", crcontactID},
    {"Photo1", File.ReadAllBytes(crphoto1)}
};
Amadeu Antunes
  • 678
  • 1
  • 8
  • 28

1 Answers1

2

If you are just looking for how to check if file exist you can use

    using System.IO;

    string fileName = Path.Combine(Environment
     .GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "yourfile.jpg");

    JObject ph1json;
    bool doesExist = File.Exists(fileName);
    if (!doesExist || string.IsNullOrEmpty(crphoto1))
    {

      ph1json = new JObject 
      {
         {"ContactID",crcontactID},
         { "Photo1",""}
      };
    } 
    else
    {
      ph1json = new JObject
     {
      {"ContactID",crcontactID},
      {"Photo1",File.ReadAllBytes(crphoto1)}
     };
    }
Amadeu Antunes
  • 678
  • 1
  • 8
  • 28