1

This is my code:

 var FinalPath = Path.Combine(DestPath, FinalFile);
 File.Copy(TempFile, FinalPath);

Destpath is "c:\Somepath\" and FinalFIle is "somefile.pdf" So FinalPath is: "c:\Somepath\somefile.pdf"

When Copy method is called i receive error (file already exists and throws an unwanted exception wich is not good).

How can i tell something like if(FinalPath.Exists = true)... ignore o continue ?

gaccerboni
  • 57
  • 7
  • 7
    Does this answer your question? [How to find out if a file exists in C# / .NET?](https://stackoverflow.com/questions/38960/how-to-find-out-if-a-file-exists-in-c-sharp-net) – Hugo Mar 17 '20 at 19:49
  • There are plenty of answers for this question. It should be closed as duplicate. – Ardahan Kisbet Mar 17 '20 at 19:51
  • 1
    If overwriting the file is OK, there's [an overload for that](https://learn.microsoft.com/en-us/dotnet/api/system.io.file.copy?view=netframework-4.8#System_IO_File_Copy_System_String_System_String_System_Boolean_) – stuartd Mar 17 '20 at 19:51
  • Thanks, i did it. – gaccerboni Mar 17 '20 at 20:27

0 Answers0