User-1660589204 posted
I have a folder from which I need to check if there are any ".trm" files and save them into DB. Below is my code:
public async void PostValuesIntoDB()
{
DirectoryInfo info = new DirectoryInfo(path);
FileInfo[] fileInfos = info.GetFiles("*.trm");
if (fileInfos != null)
{
foreach (FileInfo fileInfo in fileInfos)
{
RsbfileDetail detail = new RsbfileDetail();
detail.Filename = fileInfo.Name;
detail.FileUrl = fileInfo.FullName;
detail.FileType = fileInfo.Extension;
detail.CreatedDate = fileInfo.CreationTime;
await _rSBRepository.Add(detail);
}
}
else
{
Console.WriteLine("No trm file in destination folder");
}
}
Right now, there are no files in my folder. But when I debug with breakpoint, the execution moves into if condition, then in foreach, it goes into fileinfos and then goes out of entire code not inserting any values in DB or displaying the message in else
statement. I do not know what I did wrong. Please suggest.