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

Exists() private méthode

private Exists ( String path ) : bool
path String
Résultat bool
        public static bool Exists(String path)
        {
            try
            {
                if (path == null)
                    return false;
                if (path.Length == 0)
                    return false;

                path = Path.GetFullPath(path);
                // After normalizing, check whether path ends in directory separator.
                // Otherwise, FillAttributeInfo removes it and we may return a false positive.
                // GetFullPath should never return null
                Debug.Assert(path != null, "File.Exists: GetFullPath returned null");
                if (path.Length > 0 && PathInternal.IsDirectorySeparator(path[path.Length - 1]))
                {
                    return false;
                }

                return InternalExists(path);
            }
            catch (ArgumentException) { }
            catch (NotSupportedException) { } // Security can throw this on ":"
            catch (SecurityException) { }
            catch (IOException) { }
            catch (UnauthorizedAccessException) { }

            return false;
        }

Same methods

File::Exists ( string path ) : bool

Usage Example

Exemple #1
0
 public ImageSource Extract(File file)
 {
     try {
         if (new List<string> {".ico", ".png", ".jpg", ".gif"}.Contains(file.Extension.ToLower())) {
             if (!file.Exists()) return new BitmapImage();
             return new BitmapImage(new Uri(file.FullName));
         }
         Icon icon = ExtractIcon(ActualFile(file));
         Bitmap bmp = icon.ToBitmap();
         DestroyIcon(icon.Handle);
         var strm = new MemoryStream();
         bmp.Save(strm, ImageFormat.Png);
         return Extract(strm);
     }
     catch (ExternalException exception) {
         LogManager.WriteLog(exception);
         return new BitmapImage();
     }
     catch (DirectoryNotFoundException exception) {
         LogManager.WriteLog("Requested file: {0}", file);
         LogManager.WriteLog(exception);
         return new BitmapImage();
     }
     catch (ArgumentException exception) {
         LogManager.WriteLog("Requested file: {0}", file);
         LogManager.WriteLog(exception);
         return new BitmapImage();
     }
 }
All Usage Examples Of System.IO.File::Exists