Exemple #1
0
 public void CopyImage(string fileToCopy, string fileName = "")
 {
     //Need to check if already exists i.e if want to generate again
     if (File.Exists(fileToCopy))
     {
         if (Directory.Exists(CopyPath))
         {
             var newFileName = String.IsNullOrEmpty(fileName) ? Path.GetFileName(fileToCopy) : fileName + Path.GetExtension(fileToCopy);
             var newfile     = CopyPath + newFileName;
             // Copies files to location and will override if already exists
             // won't release the file handle until the application has been closed
             // Explore other options to allow to close file
             File.Copy(fileToCopy, newfile, true);
             FilePath  = newfile;
             ImagePath = CopyPath.Substring(CopyPath.IndexOf("\\images\\"));
             ImagePath = ImagePath + Path.GetFileName(newfile);
         }
         else
         {
             Error = "Directory to copy to does not exist";
         }
     }
     else
     {
         Error = "File to copy does not exist";
     }
 }