System.IO.FileInfo.CopyTo C# (CSharp) Method

CopyTo() public method

public CopyTo ( String destFileName ) : FileInfo
destFileName String
return FileInfo
        public FileInfo CopyTo(String destFileName)
        {
            if (destFileName == null)
                throw new ArgumentNullException(nameof(destFileName), SR.ArgumentNull_FileName);
            if (destFileName.Length == 0)
                throw new ArgumentException(SR.Argument_EmptyFileName, nameof(destFileName));
            Contract.EndContractBlock();

            destFileName = File.InternalCopy(FullPath, destFileName, false);
            return new FileInfo(destFileName, null);
        }

Same methods

FileInfo::CopyTo ( String destFileName, bool overwrite ) : FileInfo
FileInfo::CopyTo ( string destFileName ) : System.IO.FileInfo
FileInfo::CopyTo ( string destFileName, bool overwrite ) : System.IO.FileInfo

Usage Example

 public static byte[] CreateAgreementDoc(string WebPath, string AgreementNumber, string AgreementDate, string UserName, string SignerName, string TargetPosition, string TargetDepartment, string SignerShortName, string SignerPositionWithDepartment, string UserShortName)
 {
     FileInfo file = new FileInfo(Path.Combine(WebPath, @"StaffMovements\Dogovor.docx"));
     string newfilename = Path.Combine(WebPath,Guid.NewGuid().ToString()+".docx");
     var newfile = file.CopyTo(newfilename,true);
     using (var outputDocument = new TemplateProcessor(newfilename)
         .SetRemoveContentControls(true))
     {
         var documentenc = Encoding.GetEncoding(outputDocument.Document.Declaration.Encoding);
         var valuesToFill = new Content(
             new FieldContent("AgreementNumber", AgreementNumber),
             new FieldContent("AgreementDate", AgreementDate),
             new FieldContent("UserName", UserName),
             new FieldContent("Signer", SignerName),
             new FieldContent("TargetPosition", TargetPosition),
             new FieldContent("TargetDepartment", TargetDepartment),
             new FieldContent("SignerShortName", SignerShortName),
             new FieldContent("SignerPositionWithDepartment", SignerPositionWithDepartment),
             new FieldContent("UserShortName", UserShortName)
         );
         outputDocument.FillContent(valuesToFill);
         outputDocument.SaveChanges();
     }
     StreamReader reader = new StreamReader(newfilename);
     var result =  NoteCreator.ReadFull(reader.BaseStream);
     //newfile.Delete();
     return result;
 }
All Usage Examples Of System.IO.FileInfo::CopyTo