|
54 | 54 |
|
55 | 55 | ## Remarks
|
56 | 56 |
|
57 |
| -This extension method was added to .NET Core to bring the functionality that was provided by the `System.IO.DirectoryInfo.Create(System.Security.AccessControl.DirectorySecurity)` .NET Framework method. |
| 57 | +This extension method was added to .NET Core to bring the functionality that was provided by the [DirectoryInfo.Create(DirectorySecurity)](https://docs.microsoft.com/dotnet/api/system.io.directoryinfo.create?view=netframework-4.8#System_IO_DirectoryInfo_Create_System_Security_AccessControl_DirectorySecurity_) .NET Framework method. |
| 58 | +
|
| 59 | +## Examples |
| 60 | +
|
| 61 | +The following code example creates a new directory inside the user's temporary folder with the specified directory security attributes: |
| 62 | +
|
| 63 | +```csharp |
| 64 | +using System.IO; |
| 65 | +using System.Security.AccessControl; |
| 66 | +using System.Security.Principal; |
| 67 | +
|
| 68 | +namespace ConsoleApp |
| 69 | +{ |
| 70 | + class Program |
| 71 | + { |
| 72 | + static void Main() |
| 73 | + { |
| 74 | + DirectorySecurity security = new DirectorySecurity(); |
| 75 | +
|
| 76 | + SecurityIdentifier identity = new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null); |
| 77 | + FileSystemAccessRule accessRule = new FileSystemAccessRule(identity, FileSystemRights.FullControl, AccessControlType.Allow); |
| 78 | + security.AddAccessRule(accessRule); |
| 79 | +
|
| 80 | + string path = Path.Combine(Path.GetTempPath(), "directoryToCreate"); |
| 81 | +
|
| 82 | + DirectoryInfo dirInfo = new DirectoryInfo(path); |
| 83 | +
|
| 84 | + dirInfo.Create(security); |
| 85 | + } |
| 86 | + } |
| 87 | +} |
| 88 | +``` |
58 | 89 |
|
59 | 90 | ]]></format>
|
60 | 91 | </remarks>
|
@@ -102,7 +133,41 @@ This extension method was added to .NET Core to bring the functionality that was
|
102 | 133 |
|
103 | 134 | ## Remarks
|
104 | 135 |
|
105 |
| -This extension method was added to .NET Core to bring the functionality that was provided by the `System.IO.FileStream.#ctor(System.String,System.IO.FileMode,System.Security.AccessControl.FileSystemRights,System.IO.FileShare,System.Int32,System.IO.FileOptions,System.Security.AccessControl.FileSecurity)` .NET Framework constructor. |
| 136 | +This extension method was added to .NET Core to bring the functionality that was provided by: |
| 137 | +
|
| 138 | +- The [FileStream(String, FileMode, FileSystemRights, FileShare, Int32, FileOptions, FileSecurity)](https://docs.microsoft.com/dotnet/api/system.io.filestream.-ctor?view=netframework-4.8#System_IO_FileStream__ctor_System_String_System_IO_FileMode_System_Security_AccessControl_FileSystemRights_System_IO_FileShare_System_Int32_System_IO_FileOptions_System_Security_AccessControl_FileSecurity_) .NET Framework constructor. |
| 139 | +- The [File.Create(String, Int32, FileOptions, FileSecurity](https://docs.microsoft.com/en-us/dotnet/api/system.io.file.create?view=netframework-4.8#System_IO_File_Create_System_String_System_Int32_System_IO_FileOptions_System_Security_AccessControl_FileSecurity_) .NET Framework method. |
| 140 | +
|
| 141 | +## Examples |
| 142 | +
|
| 143 | +The following code example creates a new text file (with the default buffer size of 4096) inside the user's temporary folder with the specified file security attributes: |
| 144 | +
|
| 145 | +```csharp |
| 146 | +using System.IO; |
| 147 | +using System.Security.AccessControl; |
| 148 | +using System.Security.Principal; |
| 149 | +
|
| 150 | +namespace ConsoleApp |
| 151 | +{ |
| 152 | + class Program |
| 153 | + { |
| 154 | + static void Main() |
| 155 | + { |
| 156 | + FileSecurity security = new FileSecurity(); |
| 157 | +
|
| 158 | + SecurityIdentifier identity = new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null); |
| 159 | + FileSystemAccessRule accessRule = new FileSystemAccessRule(identity, FileSystemRights.FullControl, AccessControlType.Allow); |
| 160 | + security.AddAccessRule(accessRule); |
| 161 | +
|
| 162 | + string path = Path.Combine(Path.GetTempPath(), "fileToCreate.txt"); |
| 163 | +
|
| 164 | + FileInfo fileInfo = new FileInfo(path); |
| 165 | +
|
| 166 | + fileInfo.Create(FileMode.Create, FileSystemRights.FullControl, FileShare.Read, 4096, FileOptions.None, security); |
| 167 | + } |
| 168 | + } |
| 169 | +} |
| 170 | +``` |
106 | 171 |
|
107 | 172 | ]]></format>
|
108 | 173 | </remarks>
|
|
0 commit comments