InternalCopy() private méthode

private InternalCopy ( String sourceFileName, String destFileName, bool overwrite ) : String
sourceFileName String
destFileName String
overwrite bool
Résultat String
Exemple #1
0
 /// <summary>将现有文件复制到新文件,允许覆盖现有文件。</summary>
 /// <returns>为新文件;如果 <paramref name="overwrite" /> 是 true,则为现有文件的覆盖。如果文件存在且 <paramref name="overwrite" /> 为 false,则引发 <see cref="T:System.IO.IOException" />。</returns>
 /// <param name="destFileName">要复制到的新文件的名称。</param>
 /// <param name="overwrite">如果允许覆盖现有文件,则为 true;否则为 false。</param>
 /// <exception cref="T:System.ArgumentException">
 /// <paramref name="destFileName" /> 为空,仅包含空白,或包含无效字符。</exception>
 /// <exception cref="T:System.IO.IOException">发生错误,或者目标文件已经存在,并且 <paramref name="overwrite" /> 为 false。</exception>
 /// <exception cref="T:System.Security.SecurityException">调用方没有所要求的权限。</exception>
 /// <exception cref="T:System.ArgumentNullException">
 /// <paramref name="destFileName" /> 为 null。</exception>
 /// <exception cref="T:System.IO.DirectoryNotFoundException">
 /// <paramref name="destFileName" /> 中指定的目录不存在。</exception>
 /// <exception cref="T:System.UnauthorizedAccessException">传入了一个目录路径,或者正在将文件移动到另一个驱动器。</exception>
 /// <exception cref="T:System.IO.PathTooLongException">指定的路径、文件名或者两者都超出了系统定义的最大长度。例如,在基于 Windows 的平台上,路径必须小于 248 个字符,文件名必须小于 260 个字符。</exception>
 /// <exception cref="T:System.NotSupportedException">
 /// <paramref name="destFileName" /> 字符串中间有一个冒号 (:)。</exception>
 /// <filterpriority>1</filterpriority>
 /// <PermissionSet>
 ///   <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
 /// </PermissionSet>
 public FileInfo CopyTo(string destFileName, bool overwrite)
 {
     if (destFileName == null)
     {
         throw new ArgumentNullException("destFileName", Environment.GetResourceString("ArgumentNull_FileName"));
     }
     if (destFileName.Length == 0)
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), "destFileName");
     }
     destFileName = File.InternalCopy(this.FullPath, destFileName, overwrite, true);
     return(new FileInfo(destFileName, false));
 }
Exemple #2
0
        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));
            }

            return(new FileInfo(File.InternalCopy(FullPath, destFileName, false), isNormalized: true));
        }
Exemple #3
0
        // Copies an existing file to a new file. If overwrite is
        // false, then an IOException is thrown if the destination file
        // already exists.  If overwrite is true, the file is
        // overwritten.
        //
        // The caller must have certain FileIOPermissions.  The caller must have
        // Read permission to sourceFileName and Create
        // and Write permissions to destFileName.
        //
        public FileInfo CopyTo(string destFileName, bool overwrite)
        {
            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();

            return(new FileInfo(File.InternalCopy(FullPath, destFileName, overwrite), isNormalized: true));
        }
Exemple #4
0
        public FileInfo CopyTo(String destFileName)
        {
            if (destFileName == null)
            {
                throw new ArgumentNullException("destFileName", Environment.GetResourceString("ArgumentNull_FileName"));
            }
            if (destFileName.Length == 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), "destFileName");
            }
            Contract.EndContractBlock();

            destFileName = File.InternalCopy(FullPath, destFileName, false, true);
            return(new FileInfo(destFileName, false));
        }
Exemple #5
0
        // Copies an existing file to a new file. An exception is raised if the
        // destination file already exists. Use the
        // Copy(String, String, boolean) method to allow
        // overwriting an existing file.
        //
        // The caller must have certain FileIOPermissions.  The caller must have
        // Read permission to sourceFileName
        // and Write permissions to destFileName.
        //
        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));
        }
Exemple #6
0
 // Copies an existing file to a new file. If overwrite is
 // false, then an IOException is thrown if the destination file
 // already exists.  If overwrite is true, the file is
 // overwritten.
 //
 //| <include file='doc\FileInfo.uex' path='docs/doc[@for="FileInfo.CopyTo1"]/*' />
 public FileInfo CopyTo(String !destFileName, bool overwrite)
 {
     destFileName = File.InternalCopy(FullPath, destFileName, overwrite);
     return(new FileInfo(destFileName, false));
 }