Cannot create a file when that file already exists

Exception has been thrown by the target of an invocation. ---> System.IO.IOException: Cannot create a file when that file already exists.

-Check if the file already exists in the directory using below approaches :

C# code:

  1.  string path = @ "c:\temp\MySample.txt";  
  2.  bool exists=File.Exists(path))
UiPath Activity:
  1.  Use Path Exists activity and use Path Type as File
  2.  Provide the file path as per the directory
  3.  Output will be the bool exists variable

Use "If" activity in UiPath and pass the "exists" variable in it to verify.

-If the file name already exists then rename file during creating or moving it and that should fix the issue