System.IO.File.InternalCopy C# (CSharp) Méthode

InternalCopy() private méthode

private InternalCopy ( String sourceFileName, String destFileName, bool overwrite ) : String
sourceFileName String
destFileName String
overwrite bool
Résultat String
        internal static String InternalCopy(String sourceFileName, String destFileName, bool overwrite)
        {
            Debug.Assert(sourceFileName != null);
            Debug.Assert(destFileName != null);
            Debug.Assert(sourceFileName.Length > 0);
            Debug.Assert(destFileName.Length > 0);

            String fullSourceFileName = Path.GetFullPath(sourceFileName);
            String fullDestFileName = Path.GetFullPath(destFileName);

            FileSystem.Current.CopyFile(fullSourceFileName, fullDestFileName, overwrite);

            return fullDestFileName;
        }

Usage Example

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));
 }
All Usage Examples Of System.IO.File::InternalCopy