|
Cet article a fait l'objet d'une traduction automatique. Déplacez votre pointeur sur les phrases de l'article pour voir la version originale de ce texte. Informations supplémentaires.
|
Traduction
Source
|
File.SetAttributes, méthode
Espace de noms : System.IO
Assembly : mscorlib (dans mscorlib.dll)
Paramètres
- path
- Type : System.String
Chemin d'accès au fichier.
- fileAttributes
- Type : System.IO.FileAttributes
Combinaison d'opérations de bits des valeurs d'énumération.
| Exception | Condition |
|---|---|
| ArgumentException | |
| PathTooLongException | |
| NotSupportedException | |
| DirectoryNotFoundException | |
| FileNotFoundException | |
| UnauthorizedAccessException |
using System; using System.IO; using System.Text; class Test { public static void Main() { string path = @"c:\temp\MyTest.txt"; // Create the file if it exists. if (!File.Exists(path)) { File.Create(path); } FileAttributes attributes = File.GetAttributes(path); if ((attributes & FileAttributes.Hidden) == FileAttributes.Hidden) { // Show the file. attributes = RemoveAttribute(attributes, FileAttributes.Hidden); File.SetAttributes(path, attributes); Console.WriteLine("The {0} file is no longer hidden.", path); } else { // Hide the file. File.SetAttributes(path, File.GetAttributes(path) | FileAttributes.Hidden); Console.WriteLine("The {0} file is now hidden.", path); } } private static FileAttributes RemoveAttribute(FileAttributes attributes, FileAttributes attributesToRemove) { return attributes & ~attributesToRemove; } }
- FileIOPermission
pour la lecture et l'écriture de fichiers. Énumération associée : FileIOPermissionAccess.Write
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (rôle principal du serveur non pris en charge), Windows Server 2008 R2 (rôle principal du serveur pris en charge avec SP1 ou version ultérieure ; Itanium non pris en charge)
Le .NET Framework ne prend pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.