public void PublishDocument(string SourceFilePath, string TargetFolderPath, string TargetFileName, string DocumentHash) { // rename file in the same directory with Hash DocumentFileInfo dfi = this.FileInfoStore.Where(x => x.DocumentHash.Equals(DocumentHash)).FirstOrDefault(); string TargetFilePath = BuildPath(TargetFolderPath, TargetFileName); // if the document exists under the root folder... if (dfi != null) { // if target path is different // otherwise no action is required: file name and hash are identical if (!dfi.FilePath.Equals(TargetFilePath)) { Console.WriteLine("Moving file to \"{0}\".", TargetFilePath); // move the file and rename it DocumentFile.MoveFile(dfi.FilePath, TargetFilePath); } } else { try { Console.WriteLine("Copying file to \"{0}\".", TargetFilePath); // otherwise copy file from source (outside root folder) DocumentFile.CopyFile(SourceFilePath, TargetFilePath); } catch (Exception ex) { Console.WriteLine("ERROR: Unable to copy the file \"{0}\" to \"{1}\". {2}", SourceFilePath, TargetFilePath, ex.Message); } } }