About This Page
This page is part of the Azure documentation. It contains code examples and configuration instructions for working with Azure services.
Bias Analysis
Bias Types:
⚠️
windows_first
⚠️
missing_linux_example
Summary:
The documentation demonstrates a Windows bias in the 'Work with Azure Files using System.IO' section. While it mentions both Windows and Linux mounting guides, all code examples use Windows-style paths (e.g., Z:\file-share) and reference only the Windows SMB mount point. There are no examples or code snippets showing how to use System.IO with a Linux-mounted file share (e.g., /mnt/file-share). This may make Linux developers feel less supported or unsure about parity.
Recommendations:
- Add parallel Linux examples for mounting and accessing Azure Files, including code snippets using Linux file paths (e.g., '/mnt/file-share').
- In all System.IO code examples, provide both Windows and Linux path variants, or use a variable to indicate the path can be platform-specific.
- When referencing mounting instructions, list Linux and Windows equally (not always Windows first), or group them together neutrally.
- Explicitly state that all System.IO examples work identically on Linux, and demonstrate this with at least one Linux-specific example.
- Consider including a table or note summarizing any OS-specific considerations for .NET developers using Azure Files.
Create pull request
Flagged Code Snippets
using System.IO;
string fileSharePath = @"Z:\file-share";
LockFile(Path.Combine(fileSharePath, "test.txt"));
static void LockFile(string filePath)
{
try
{
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite, FileShare.None))
{
Console.WriteLine("File locked.");
// Do something with file, press Enter to close the stream and release the lock
Console.ReadLine();
fs.Close();
Console.WriteLine("File closed.");
}
}
catch (IOException ex)
{
Console.WriteLine(ex.Message);
}
}
string fileSharePath = @"Z:\file-share";
using System.IO;
string fileSharePath = @"Z:\file-share";
EnumerateDirectories(@"Z:\file-share");
static void EnumerateDirectories(string path)
{
try
{
List<string> dirs = new List<string>(Directory.EnumerateDirectories(path));
foreach (var dir in dirs)
{
Console.WriteLine($"{dir.Substring(dir.LastIndexOf(Path.DirectorySeparatorChar) + 1)}");
}
Console.WriteLine($"{dirs.Count} directories found.");
}
catch (UnauthorizedAccessException ex)
{
Console.WriteLine(ex.Message);
}
catch (PathTooLongException ex)
{
Console.WriteLine(ex.Message);
}
}
using System.IO;
string fileSharePath = @"Z:\file-share";
WriteToFile(fileSharePath, "test.txt");
static void WriteToFile(string fileSharePath, string fileName)
{
string textToWrite = "First line" + Environment.NewLine;
string filePath = Path.Combine(fileSharePath, fileName);
File.WriteAllText(filePath, textToWrite);
string[] textToAppend = { "Second line", "Third line" };
File.AppendAllLines(filePath, textToAppend);
}
using System.IO;
using System.Security.AccessControl;
string fileSharePath = @"Z:\file-share";
string fileName = "test.txt";
string filePath = Path.Combine(fileSharePath, fileName);
EnumerateFileACLs(filePath);
static void EnumerateFileACLs(string filePath)
{
FileInfo fileInfo = new FileInfo(filePath);
// For directories, use DirectorySecurity instead of FileSecurity
FileSecurity fSecurity = FileSystemAclExtensions.GetAccessControl(fileInfo);
// List all access rules for the file
foreach (FileSystemAccessRule rule in fSecurity.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount)))
{
Console.WriteLine($"Identity: {rule.IdentityReference.Value}");
Console.WriteLine($"Access Control Type: {rule.AccessControlType}");
Console.WriteLine($"File System Rights: {rule.FileSystemRights}");
Console.WriteLine();
}
}