Ejemplo n.º 1
0
        public static void DeleteFile(string path)
        {
            string prefixedPath;

            if (path.StartsWith(@"\\"))
            {
                prefixedPath = path.Replace(@"\\", uncPrefix);
            }
            else
            {
                prefixedPath = normalPrefix + path;
            }
            try
            {
                Win32Native.DeleteFileW(prefixedPath);
            }
            catch
            {
                int hr = Marshal.GetLastWin32Error();
                if (hr != 2 && hr != 0x12)
                {
                    throw new Win32Exception(hr);
                    //Console.WriteLine("{0}:  {1}", path, (new Win32Exception(hr)).Message);
                }
            }
        }
        public static void DeleteFile(string path)
        {
            string prefixedPath;

            if (path.StartsWith(@"\\"))
            {
                prefixedPath = path.Replace(@"\\", uncPrefix);
            }
            else
            {
                prefixedPath = normalPrefix + path;
            }

            bool success = Win32Native.DeleteFileW(prefixedPath);

            if (!success)
            {
                int lastError = Marshal.GetLastWin32Error();
                throw new Win32Exception(lastError);
            }
        }