GetExceptionFromLastWin32Error() static private méthode

static private GetExceptionFromLastWin32Error ( ) : Exception
Résultat System.Exception
Exemple #1
0
 public static void Move(Path sourcePath, Path targetPath)
 {
     if (!NativeMethods.MoveFile(sourcePath.FullPath, targetPath.FullPath))
     {
         throw LongPathCommon.GetExceptionFromLastWin32Error();
     }
 }
Exemple #2
0
 /// <summary>
 ///     Deletes the specified empty directory.
 /// </summary>
 /// <param name = "path">
 ///     A <see cref = "String" /> containing the path of the directory to delete.
 /// </param>
 /// <exception cref = "ArgumentNullException">
 ///     <paramref name = "path" /> is <see langword = "null" />.
 /// </exception>
 /// <exception cref = "ArgumentException">
 ///     <paramref name = "path" /> is an empty string (""), contains only white
 ///     space, or contains one or more invalid characters as defined in
 ///     <see cref = "System.IO.Path.GetInvalidPathChars()" />.
 ///     <para>
 ///         -or-
 ///     </para>
 ///     <paramref name = "path" /> contains one or more components that exceed
 ///     the drive-defined maximum length. For example, on Windows-based
 ///     platforms, components must not exceed 255 characters.
 /// </exception>
 /// <exception cref = "PathTooLongException">
 ///     <paramref name = "path" /> exceeds the system-defined maximum length.
 ///     For example, on Windows-based platforms, paths must not exceed
 ///     32,000 characters.
 /// </exception>
 /// <exception cref = "DirectoryNotFoundException">
 ///     <paramref name = "path" /> could not be found.
 /// </exception>
 /// <exception cref = "UnauthorizedAccessException">
 ///     The caller does not have the required access permissions.
 ///     <para>
 ///         -or-
 ///     </para>
 ///     <paramref name = "path" /> refers to a directory that is read-only.
 /// </exception>
 /// <exception cref = "IOException">
 ///     <paramref name = "path" /> is a file.
 ///     <para>
 ///         -or-
 ///     </para>
 ///     <paramref name = "path" /> refers to a directory that is not empty.
 ///     <para>
 ///         -or-
 ///     </para>
 ///     <paramref name = "path" /> refers to a directory that is in use.
 ///     <para>
 ///         -or-
 ///     </para>
 ///     <paramref name = "path" /> specifies a device that is not ready.
 /// </exception>
 public static void Delete(Path path)
 {
     if (!NativeMethods.RemoveDirectory(path.LongFullPath))
     {
         throw LongPathCommon.GetExceptionFromLastWin32Error();
     }
 }
Exemple #3
0
        /// <summary>
        ///     Copies the specified file to a specified new file, indicating whether to overwrite an existing file.
        /// </summary>
        /// <param name = "sourcePath">
        ///     A <see cref = "String" /> containing the path of the file to copy.
        /// </param>
        /// <param name = "destinationPath">
        ///     A <see cref = "String" /> containing the new path of the file.
        /// </param>
        /// <param name = "overwrite">
        ///     <see langword = "true" /> if <paramref name = "destinationPath" /> should be overwritten
        ///     if it refers to an existing file, otherwise, <see langword = "false" />.
        /// </param>
        /// <exception cref = "ArgumentNullException">
        ///     <paramref name = "sourcePath" /> and/or <paramref name = "destinationPath" /> is
        ///     <see langword = "null" />.
        /// </exception>
        /// <exception cref = "ArgumentException">
        ///     <paramref name = "sourcePath" /> and/or <paramref name = "destinationPath" /> is
        ///     an empty string (""), contains only white space, or contains one or more
        ///     invalid characters as defined in <see cref = "System.IO.Path.GetInvalidPathChars()" />.
        ///     <para>
        ///         -or-
        ///     </para>
        ///     <paramref name = "sourcePath" /> and/or <paramref name = "destinationPath" />
        ///     contains one or more components that exceed the drive-defined maximum length.
        ///     For example, on Windows-based platforms, components must not exceed 255 characters.
        /// </exception>
        /// <exception cref = "PathTooLongException">
        ///     <paramref name = "sourcePath" /> and/or <paramref name = "destinationPath" />
        ///     exceeds the system-defined maximum length. For example, on Windows-based platforms,
        ///     paths must not exceed 32,000 characters.
        /// </exception>
        /// <exception cref = "FileNotFoundException">
        ///     <paramref name = "sourcePath" /> could not be found.
        /// </exception>
        /// <exception cref = "DirectoryNotFoundException">
        ///     One or more directories in <paramref name = "sourcePath" /> and/or
        ///     <paramref name = "destinationPath" /> could not be found.
        /// </exception>
        /// <exception cref = "UnauthorizedAccessException">
        ///     The caller does not have the required access permissions.
        ///     <para>
        ///         -or-
        ///     </para>
        ///     <paramref name = "overwrite" /> is true and <paramref name = "destinationPath" /> refers to a
        ///     file that is read-only.
        /// </exception>
        /// <exception cref = "IOException">
        ///     <paramref name = "overwrite" /> is false and <paramref name = "destinationPath" /> refers to
        ///     a file that already exists.
        ///     <para>
        ///         -or-
        ///     </para>
        ///     <paramref name = "sourcePath" /> and/or <paramref name = "destinationPath" /> is a
        ///     directory.
        ///     <para>
        ///         -or-
        ///     </para>
        ///     <paramref name = "overwrite" /> is true and <paramref name = "destinationPath" /> refers to
        ///     a file that already exists and is in use.
        ///     <para>
        ///         -or-
        ///     </para>
        ///     <paramref name = "sourcePath" /> refers to a file that is in use.
        ///     <para>
        ///         -or-
        ///     </para>
        ///     <paramref name = "sourcePath" /> and/or <paramref name = "destinationPath" /> specifies
        ///     a device that is not ready.
        /// </exception>
        public static void Copy(Path sourcePath, Path destinationPath, bool overwrite)
        {
            var normalizedSourcePath      = LongPathCommon.NormalizeLongPath(sourcePath.FullPath, "sourcePath");
            var normalizedDestinationPath = LongPathCommon.NormalizeLongPath(destinationPath.FullPath, "destinationPath");

            if (!NativeMethods.CopyFile(normalizedSourcePath, normalizedDestinationPath, !overwrite))
            {
                throw LongPathCommon.GetExceptionFromLastWin32Error();
            }
        }
Exemple #4
0
        private static SafeFileHandle GetFileHandle(string normalizedPath, FileMode mode, FileAccess access, FileShare share,
                                                    FileOptions options)
        {
            var handle = NativeMethods.CreateFile(normalizedPath, access.ToNative(), share.ToNative(), IntPtr.Zero,
                                                  mode.ToNative(),
                                                  options.ToNative(), IntPtr.Zero);

            if (handle.IsInvalid)
            {
                throw LongPathCommon.GetExceptionFromLastWin32Error();
            }

            return(handle);
        }