public static int CopyFiles(int packageId, string[] files, string destFolder) { // check account int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive); if (accountCheck < 0) { return(accountCheck); } // check package int packageCheck = SecurityContext.CheckPackage(packageId, DemandPackage.IsActive); if (packageCheck < 0) { return(packageCheck); } // check dest folder exists if (!DirectoryExists(packageId, destFolder)) { return(BusinessErrorCodes.ERROR_FILE_DEST_FOLDER_NONEXISTENT); } // place log record TaskManager.StartTask("FILES", "COPY_FILES", packageId); TaskManager.WriteParameter("Destination folder", destFolder); if (files != null) { foreach (string file in files) { TaskManager.Write(file); } } try { OS.OperatingSystem os = GetOS(packageId); string destFullFolder = GetFullPackagePath(packageId, destFolder); for (int i = 0; i < files.Length; i++) { string srcFilePath = GetFullPackagePath(packageId, files[i]); string destFilePath = Path.Combine(destFullFolder, srcFilePath.Substring(srcFilePath.LastIndexOf("\\") + 1)); if (srcFilePath == destFilePath) { return(BusinessErrorCodes.ERROR_FILE_COPY_TO_SELF); } //Check that we're not trying to copy a folder into its own subfolder else if (destFilePath.StartsWith(srcFilePath + "\\")) { return(BusinessErrorCodes.ERROR_FILE_COPY_TO_OWN_SUBFOLDER); } else { os.CopyFile(srcFilePath, destFilePath); } } return(0); } catch (Exception ex) { //Log and return a generic error rather than throwing an exception TaskManager.WriteError(ex); return(BusinessErrorCodes.ERROR_FILE_GENERIC_LOGGED); } finally { TaskManager.CompleteTask(); } }