public void MoveTo(String destFileName) { if (destFileName == null) { throw new ArgumentNullException("destFileName"); } if (destFileName.Length == 0) { throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), "destFileName"); } Contract.EndContractBlock(); String fullDestFileName = Path.GetFullPathInternal(destFileName); #if FEATURE_CORECLR FileSecurityState sourceState = new FileSecurityState(FileSecurityStateAccess.Write | FileSecurityStateAccess.Read, DisplayPath, FullPath); FileSecurityState destState = new FileSecurityState(FileSecurityStateAccess.Write, destFileName, fullDestFileName); sourceState.EnsureState(); destState.EnsureState(); #else new FileIOPermission(FileIOPermissionAccess.Write | FileIOPermissionAccess.Read, new String[] { FullPath }, false, false).Demand(); FileIOPermission.QuickDemand(FileIOPermissionAccess.Write, fullDestFileName, false, false); #endif if (!Win32Native.MoveFile(FullPath, fullDestFileName)) { __Error.WinIOError(); } FullPath = fullDestFileName; OriginalPath = destFileName; _name = Path.GetFileName(fullDestFileName); DisplayPath = GetDisplayPath(destFileName); // Flush any cached information about the file. _dataInitialised = -1; }
// Moves a specified file to a new location and potentially a new file name. // This method does work across volumes. // // The caller must have certain FileIOPermissions. The caller must // have Read and Write permission to // sourceFileName and Write // permissions to destFileName. // /// <include file='doc\File.uex' path='docs/doc[@for="File.Move"]/*' /> public static void Move(String sourceFileName, String destFileName) { if (sourceFileName == null || destFileName == null) { throw new ArgumentNullException((sourceFileName == null ? "sourceFileName" : "destFileName"), Environment.GetResourceString("ArgumentNull_FileName")); } if (sourceFileName.Length == 0 || destFileName.Length == 0) { throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), (sourceFileName.Length == 0 ? "sourceFileName" : "destFileName")); } String fullSourceFileName = Path.GetFullPathInternal(sourceFileName); new FileIOPermission(FileIOPermissionAccess.Write | FileIOPermissionAccess.Read, new String[] { fullSourceFileName }, false, false).Demand(); String fullDestFileName = Path.GetFullPathInternal(destFileName); new FileIOPermission(FileIOPermissionAccess.Write, new String[] { fullDestFileName }, false, false).Demand(); if (!InternalExists(fullSourceFileName)) { __Error.WinIOError(Win32Native.ERROR_FILE_NOT_FOUND, sourceFileName); } if (!Win32Native.MoveFile(fullSourceFileName, fullDestFileName)) { int errorCode = Marshal.GetLastWin32Error(); __Error.WinIOError(errorCode, destFileName); } }
internal static void Move(String sourceFileName, String destFileName) { Contract.Requires(sourceFileName != null); Contract.Requires(destFileName != null); Contract.Requires(sourceFileName.Length > 0); Contract.Requires(destFileName.Length > 0); String fullSourceFileName = LongPath.NormalizePath(sourceFileName); new FileIOPermission(FileIOPermissionAccess.Write | FileIOPermissionAccess.Read, new String[] { fullSourceFileName }, false, false).Demand(); String fullDestFileName = LongPath.NormalizePath(destFileName); new FileIOPermission(FileIOPermissionAccess.Write, new String[] { fullDestFileName }, false, false).Demand(); if (!LongPathFile.InternalExists(fullSourceFileName)) { __Error.WinIOError(Win32Native.ERROR_FILE_NOT_FOUND, fullSourceFileName); } String tempSourceFileName = Path.AddLongPathPrefix(fullSourceFileName); String tempDestFileName = Path.AddLongPathPrefix(fullDestFileName); if (!Win32Native.MoveFile(tempSourceFileName, tempDestFileName)) { __Error.WinIOError(); } }
public void MoveTo(String destFileName) { if (destFileName == null) { throw new ArgumentNullException(nameof(destFileName)); } if (destFileName.Length == 0) { throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), nameof(destFileName)); } Contract.EndContractBlock(); string fullDestFileName = Path.GetFullPath(destFileName); FileSecurityState sourceState = new FileSecurityState(FileSecurityStateAccess.Write | FileSecurityStateAccess.Read, DisplayPath, FullPath); FileSecurityState destState = new FileSecurityState(FileSecurityStateAccess.Write, destFileName, fullDestFileName); sourceState.EnsureState(); destState.EnsureState(); if (!Win32Native.MoveFile(FullPath, fullDestFileName)) { __Error.WinIOError(); } FullPath = fullDestFileName; OriginalPath = destFileName; _name = Path.GetFileName(fullDestFileName); DisplayPath = GetDisplayPath(destFileName); // Flush any cached information about the file. _dataInitialised = -1; }
private static void InternalMove(String sourceFileName, String destFileName) { if (sourceFileName == null) { throw new ArgumentNullException(nameof(sourceFileName), Environment.GetResourceString("ArgumentNull_FileName")); } if (destFileName == null) { throw new ArgumentNullException(nameof(destFileName), Environment.GetResourceString("ArgumentNull_FileName")); } if (sourceFileName.Length == 0) { throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), nameof(sourceFileName)); } if (destFileName.Length == 0) { throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), nameof(destFileName)); } Contract.EndContractBlock(); String fullSourceFileName = Path.GetFullPath(sourceFileName); String fullDestFileName = Path.GetFullPath(destFileName); if (!InternalExists(fullSourceFileName)) { __Error.WinIOError(Win32Native.ERROR_FILE_NOT_FOUND, fullSourceFileName); } if (!Win32Native.MoveFile(fullSourceFileName, fullDestFileName)) { __Error.WinIOError(); } }
// Moves a given file to a new location and potentially a new file name. // This method does work across volumes. // // The caller must have certain FileIOPermissions. The caller must // have Read and Write permission to // sourceFileName and Write // permissions to destFileName. // /// <include file='doc\FileInfo.uex' path='docs/doc[@for="FileInfo.MoveTo"]/*' /> public void MoveTo(String destFileName) { if (destFileName == null) { throw new ArgumentNullException("destFileName"); } if (destFileName.Length == 0) { throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), "destFileName"); } new FileIOPermission(FileIOPermissionAccess.Write | FileIOPermissionAccess.Read, new String[] { FullPath }, false, false).Demand(); String fullDestFileName = Path.GetFullPathInternal(destFileName); new FileIOPermission(FileIOPermissionAccess.Write, new String[] { fullDestFileName }, false, false).Demand(); if (!Win32Native.MoveFile(FullPath, fullDestFileName)) { __Error.WinIOError(); } FullPath = fullDestFileName; OriginalPath = destFileName; _name = Path.GetFileName(fullDestFileName); // Flush any cached information about the file. _dataInitialised = -1; }
internal static void Move(String sourceDirName, String destDirName) { Contract.Requires(sourceDirName != null); Contract.Requires(destDirName != null); Contract.Requires(sourceDirName.Length != 0); Contract.Requires(destDirName.Length != 0); String fullsourceDirName = LongPath.NormalizePath(sourceDirName); String sourcePath = GetDemandDir(fullsourceDirName, false); if (sourcePath.Length >= Path.MaxLongPath) { throw new PathTooLongException(Environment.GetResourceString("IO.PathTooLong")); } String fulldestDirName = LongPath.NormalizePath(destDirName); String destPath = GetDemandDir(fulldestDirName, false); if (destPath.Length >= Path.MaxLongPath) { throw new PathTooLongException(Environment.GetResourceString("IO.PathTooLong")); } new FileIOPermission(FileIOPermissionAccess.Write | FileIOPermissionAccess.Read, new String[] { sourcePath }, false, false).Demand(); new FileIOPermission(FileIOPermissionAccess.Write, new String[] { destPath }, false, false).Demand(); if (String.Compare(sourcePath, destPath, StringComparison.OrdinalIgnoreCase) == 0) { throw new IOException(Environment.GetResourceString("IO.IO_SourceDestMustBeDifferent")); } String sourceRoot = LongPath.GetPathRoot(sourcePath); String destinationRoot = LongPath.GetPathRoot(destPath); if (String.Compare(sourceRoot, destinationRoot, StringComparison.OrdinalIgnoreCase) != 0) { throw new IOException(Environment.GetResourceString("IO.IO_SourceDestMustHaveSameRoot")); } String tempSourceDirName = Path.AddLongPathPrefix(sourceDirName); String tempDestDirName = Path.AddLongPathPrefix(destDirName); if (!Win32Native.MoveFile(tempSourceDirName, tempDestDirName)) { int hr = Marshal.GetLastWin32Error(); if (hr == Win32Native.ERROR_FILE_NOT_FOUND) // Source dir not found { hr = Win32Native.ERROR_PATH_NOT_FOUND; __Error.WinIOError(hr, fullsourceDirName); } // This check was originally put in for Win9x (unfortunately without special casing it to be for Win9x only). We can't change the NT codepath now for backcomp reasons. if (hr == Win32Native.ERROR_ACCESS_DENIED) // WinNT throws IOException. This check is for Win9x. We can't change it for backcomp. { throw new IOException(Environment.GetResourceString("UnauthorizedAccess_IODenied_Path", sourceDirName), Win32Native.MakeHRFromErrorCode(hr)); } __Error.WinIOError(hr, String.Empty); } }
private static void InternalMove(String sourceFileName, String destFileName, bool checkHost) { if (sourceFileName == null) { throw new ArgumentNullException(nameof(sourceFileName), Environment.GetResourceString("ArgumentNull_FileName")); } if (destFileName == null) { throw new ArgumentNullException(nameof(destFileName), Environment.GetResourceString("ArgumentNull_FileName")); } if (sourceFileName.Length == 0) { throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), nameof(sourceFileName)); } if (destFileName.Length == 0) { throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), nameof(destFileName)); } Contract.EndContractBlock(); String fullSourceFileName = Path.GetFullPath(sourceFileName); String fullDestFileName = Path.GetFullPath(destFileName); if (checkHost) { FileSecurityState sourceState = new FileSecurityState(FileSecurityStateAccess.Write | FileSecurityStateAccess.Read, sourceFileName, fullSourceFileName); FileSecurityState destState = new FileSecurityState(FileSecurityStateAccess.Write, destFileName, fullDestFileName); sourceState.EnsureState(); destState.EnsureState(); } if (!InternalExists(fullSourceFileName)) { __Error.WinIOError(Win32Native.ERROR_FILE_NOT_FOUND, fullSourceFileName); } if (!Win32Native.MoveFile(fullSourceFileName, fullDestFileName)) { __Error.WinIOError(); } }
// Moves a given file to a new location and potentially a new file name. // This method does work across volumes. // // The caller must have certain FileIOPermissions. The caller must // have Read and Write permission to // sourceFileName and Write // permissions to destFileName. // /// <include file='doc\FileInfo.uex' path='docs/doc[@for="FileInfo.MoveTo"]/*' /> public void MoveTo(String destFileName) { if (destFileName == null) { throw new ArgumentNullException("destFileName"); } if (destFileName.Length == 0) { throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), "destFileName"); } new FileIOPermission(FileIOPermissionAccess.Write | FileIOPermissionAccess.Read, new String[] { FullPath }, false, false).Demand(); destFileName = Path.GetFullPathInternal(destFileName); new FileIOPermission(FileIOPermissionAccess.Write, new String[] { destFileName }, false, false).Demand(); if (!Win32Native.MoveFile(FullPath, destFileName)) { __Error.WinIOError(); } FullPath = destFileName; _name = Path.GetFileName(destFileName); }