{"id":99,"date":"2010-11-10T00:58:02","date_gmt":"2010-11-10T07:58:02","guid":{"rendered":"https:\/\/wordpress-1325650-4848760.cloudwaysapps.com\/?p=99"},"modified":"2025-04-24T12:47:58","modified_gmt":"2025-04-24T16:47:58","slug":"drive-info-csharp","status":"publish","type":"post","link":"https:\/\/codesamplez.com\/programming\/drive-info-csharp","title":{"rendered":"C# DriveInfo Class: Access Drive Information Like a Pro"},"content":{"rendered":"\n<p>Ever needed to get information about the drives connected to your system? I&#8217;ve been there, and the C# DriveInfo class is absolutely your best friend for this task. It&#8217;s an incredibly powerful tool in the <code>System.IO<\/code> namespace that gives you instant access to everything you want to know about drives on your computer.<\/p>\n\n\n\n<p>When I first started working with file systems in C#, I was amazed at how easy Microsoft made it to extract critical drive information. Whether you&#8217;re building a disk analyzer, a backup utility, or just need to check available space before writing files, the DriveInfo class handles it all with minimal code.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What You&#8217;ll Learn in This Guide<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>How to get a complete list of all drives on your system<\/li>\n\n\n\n<li>Checking drive properties like available space, format, and type<\/li>\n\n\n\n<li>Working with drive information effectively in your applications<\/li>\n\n\n\n<li>Real-world examples you can copy and use immediately<\/li>\n<\/ul>\n\n\n\n<p>Let&#8217;s dive right in!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Getting Started with C# DriveInfo<\/h2>\n\n\n\n<p>The DriveInfo class is part of the <code>System.IO<\/code> namespace, so you&#8217;ll need to include that at the top of your file:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">using<\/span> <span class=\"hljs-selector-tag\">System<\/span>;\n<span class=\"hljs-selector-tag\">using<\/span> <span class=\"hljs-selector-tag\">System<\/span><span class=\"hljs-selector-class\">.IO<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The beauty of DriveInfo is how straightforward it is to use. With just a few lines of code, you can extract valuable information about any drive on your system.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">List All Drives on Your System<\/h2>\n\n\n\n<p><strong>Question: How do I list every drive and its free space in C#?<\/strong><\/p>\n\n\n\n<p>One of the most common tasks is getting information about all available drives. Here&#8217;s the simplest way to do it:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">DriveInfo&#91;] allDrives = DriveInfo.GetDrives();\n\n<span class=\"hljs-keyword\">foreach<\/span> (DriveInfo drive in allDrives)\n{\n    Console.WriteLine($<span class=\"hljs-string\">\"Drive: {drive.Name}\"<\/span>);\n    \n    <span class=\"hljs-comment\">\/\/ Check if drive is ready before accessing other properties<\/span>\n    <span class=\"hljs-keyword\">if<\/span> (drive.IsReady)\n    {\n        Console.WriteLine($<span class=\"hljs-string\">\"  Volume Label: {drive.VolumeLabel}\"<\/span>);\n        Console.WriteLine($<span class=\"hljs-string\">\"  Drive Type: {drive.DriveType}\"<\/span>);\n        Console.WriteLine($<span class=\"hljs-string\">\"  Drive Format: {drive.DriveFormat}\"<\/span>);\n        Console.WriteLine($<span class=\"hljs-string\">\"  Total Size: {drive.TotalSize \/ 1073741824} GB\"<\/span>);\n        Console.WriteLine($<span class=\"hljs-string\">\"  Available Free Space: {drive.AvailableFreeSpace \/ 1073741824} GB\"<\/span>);\n    }\n    Console.WriteLine();\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The code above will give you a complete list of drives along with their properties. Notice how I&#8217;ve divided the size values by <code>1073741824 (1024^3)<\/code> to convert bytes to gigabytes for better readability.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Important DriveInfo Properties You Should Know<\/h2>\n\n\n\n<p>The <code>DriveInfo<\/code> class offers several useful properties that provide detailed information about a drive:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>Property<\/td><td>Description<\/td><\/tr><tr><td>Name<\/td><td>The name of the drive (like &#8220;C:\\&#8221;)<\/td><\/tr><tr><td>DriveType<\/td><td>The type of drive (Fixed, Network, Removable, etc.)<\/td><\/tr><tr><td>DriveFormat<\/td><td>The file system format (NTFS, FAT32, exFAT, etc.)<\/td><\/tr><tr><td>IsReady<\/td><td>Whether the drive is ready for reading\/writing<\/td><\/tr><tr><td>AvailableFreeSpace<\/td><td>Free space available to the current user<\/td><\/tr><tr><td>TotalFreeSpace<\/td><td>Total free space on the drive<\/td><\/tr><tr><td>TotalSize<\/td><td>Total size of the drive<\/td><\/tr><tr><td>VolumeLabel<\/td><td>The volume label of the drive<\/td><\/tr><tr><td>RootDirectory<\/td><td>Gets the root directory of the drive<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Always Check IsReady Before Accessing Properties<\/h2>\n\n\n\n<p>This is extremely important! As we don&#8217;t know the state of the drive readyness(could be in the middle of being connected with <a href=\"https:\/\/codesamplez.com\/programming\/serial-port-communication-c-sharp\" target=\"_blank\" rel=\"noreferrer noopener\">external port<\/a> etc,), make sure to always check the <code>IsReady<\/code> property before trying to access other properties like TotalSize or DriveFormat. If a drive isn&#8217;t ready (like an empty DVD drive or disconnected network drive), you&#8217;ll get an IOException when trying to access these properties.<\/p>\n\n\n\n<p>Here&#8217;s the safe way to do it:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">DriveInfo drive = <span class=\"hljs-keyword\">new<\/span> DriveInfo(<span class=\"hljs-string\">\"C\"<\/span>);\n\n<span class=\"hljs-keyword\">if<\/span> (drive.IsReady)\n{\n    <span class=\"hljs-comment\">\/\/ Now it's safe to access properties<\/span>\n    Console.WriteLine($<span class=\"hljs-string\">\"Total size: {drive.TotalSize \/ 1073741824} GB\"<\/span>);\n}\n<span class=\"hljs-keyword\">else<\/span>\n{\n    Console.WriteLine(<span class=\"hljs-string\">\"Drive is not ready.\"<\/span>);\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Different Drive Types in C#<\/h2>\n\n\n\n<p>The <code>DriveInfo.DriveType<\/code> property returns an enumeration value that indicates the type of drive. Here are the possible values:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-keyword\">foreach<\/span> (DriveInfo drive in DriveInfo.GetDrives())\n{\n    <span class=\"hljs-keyword\">switch<\/span> (drive.DriveType)\n    {\n        <span class=\"hljs-keyword\">case<\/span> DriveType.Fixed:\n            Console.WriteLine($<span class=\"hljs-string\">\"{drive.Name} is a fixed drive\"<\/span>);\n            <span class=\"hljs-keyword\">break<\/span>;\n        <span class=\"hljs-keyword\">case<\/span> DriveType.Removable:\n            Console.WriteLine($<span class=\"hljs-string\">\"{drive.Name} is a removable drive\"<\/span>);\n            <span class=\"hljs-keyword\">break<\/span>;\n        <span class=\"hljs-keyword\">case<\/span> DriveType.Network:\n            Console.WriteLine($<span class=\"hljs-string\">\"{drive.Name} is a network drive\"<\/span>);\n            <span class=\"hljs-keyword\">break<\/span>;\n        <span class=\"hljs-keyword\">case<\/span> DriveType.CDRom:\n            Console.WriteLine($<span class=\"hljs-string\">\"{drive.Name} is a CD\/DVD drive\"<\/span>);\n            <span class=\"hljs-keyword\">break<\/span>;\n        <span class=\"hljs-keyword\">case<\/span> DriveType.Ram:\n            Console.WriteLine($<span class=\"hljs-string\">\"{drive.Name} is a RAM disk\"<\/span>);\n            <span class=\"hljs-keyword\">break<\/span>;\n        <span class=\"hljs-keyword\">default<\/span>:\n            Console.WriteLine($<span class=\"hljs-string\">\"{drive.Name} is an unknown drive type\"<\/span>);\n            <span class=\"hljs-keyword\">break<\/span>;\n    }\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Real-World Example: Check Available Space Before Saving Files<\/h2>\n\n\n\n<p>One practical application of the DriveInfo class is checking if there&#8217;s enough space before saving large files:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-keyword\">public<\/span> bool IsEnoughSpaceAvailable(string driveName, long requiredSpace)\n{\n    <span class=\"hljs-keyword\">try<\/span>\n    {\n        DriveInfo drive = <span class=\"hljs-keyword\">new<\/span> DriveInfo(driveName);\n        \n        <span class=\"hljs-keyword\">if<\/span> (!drive.IsReady)\n            <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-keyword\">false<\/span>;\n            \n        <span class=\"hljs-keyword\">return<\/span> drive.AvailableFreeSpace &gt;= requiredSpace;\n    }\n    <span class=\"hljs-keyword\">catch<\/span> (<span class=\"hljs-keyword\">Exception<\/span> ex)\n    {\n        Console.WriteLine($<span class=\"hljs-string\">\"Error checking drive space: {ex.Message}\"<\/span>);\n        <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-keyword\">false<\/span>;\n    }\n}\n\n<span class=\"hljs-comment\">\/\/ Usage example<\/span>\n<span class=\"hljs-keyword\">if<\/span> (IsEnoughSpaceAvailable(<span class=\"hljs-string\">\"C\"<\/span>, <span class=\"hljs-number\">1024<\/span> * <span class=\"hljs-number\">1024<\/span> * <span class=\"hljs-number\">100<\/span>)) &lt;em&gt;<span class=\"hljs-comment\">\/\/ 100 MB&lt;\/em&gt;<\/span>\n{\n    <span class=\"hljs-comment\">\/\/ Safe to save file<\/span>\n    SaveLargeFile();\n}\n<span class=\"hljs-keyword\">else<\/span>\n{\n    Console.WriteLine(<span class=\"hljs-string\">\"Not enough space available!\"<\/span>);\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Finding the Drive with the Most Free Space<\/h2>\n\n\n\n<p>Another common scenario is finding the drive with the most available space:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-keyword\">public<\/span> DriveInfo GetDriveWithMostFreeSpace()\n{\n    DriveInfo&#91;] drives = DriveInfo.GetDrives();\n    DriveInfo driveWithMostSpace = <span class=\"hljs-keyword\">null<\/span>;\n    long maxFreeSpace = <span class=\"hljs-number\">0<\/span>;\n\n    <span class=\"hljs-keyword\">foreach<\/span> (DriveInfo drive in drives)\n    {\n        <span class=\"hljs-keyword\">if<\/span> (drive.IsReady &amp;&amp; drive.DriveType == DriveType.Fixed &amp;&amp; drive.AvailableFreeSpace &gt; maxFreeSpace)\n        {\n            maxFreeSpace = drive.AvailableFreeSpace;\n            driveWithMostSpace = drive;\n        }\n    }\n\n    <span class=\"hljs-keyword\">return<\/span> driveWithMostSpace;\n}\n\n<span class=\"hljs-comment\">\/\/ Usage<\/span>\nDriveInfo bestDrive = GetDriveWithMostFreeSpace();\n<span class=\"hljs-keyword\">if<\/span> (bestDrive != <span class=\"hljs-keyword\">null<\/span>)\n{\n    Console.WriteLine($<span class=\"hljs-string\">\"Best drive for storage: {bestDrive.Name} with {bestDrive.AvailableFreeSpace \/ 1073741824} GB free\"<\/span>);\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Getting Drive Information Using a Path<\/h2>\n\n\n\n<p>Sometimes you might have a file path and want to know about the drive it&#8217;s located on:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-keyword\">public<\/span> DriveInfo GetDriveInfoFromPath(string path)\n{\n    <span class=\"hljs-comment\">\/\/ Extract the drive letter from the path<\/span>\n    string driveLetter = Path.GetPathRoot(path).Replace(<span class=\"hljs-string\">\":\\\\\"<\/span>, <span class=\"hljs-string\">\"\"<\/span>);\n    <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-keyword\">new<\/span> DriveInfo(driveLetter);\n}\n\n<span class=\"hljs-comment\">\/\/ Usage<\/span>\nstring filePath = @<span class=\"hljs-string\">\"C:\\Users\\Documents\\myfile.txt\"<\/span>;\nDriveInfo drive = GetDriveInfoFromPath(filePath);\n\n<span class=\"hljs-keyword\">if<\/span> (drive.IsReady)\n{\n    Console.WriteLine($<span class=\"hljs-string\">\"The file is on drive {drive.Name} which has {drive.AvailableFreeSpace \/ 1073741824} GB free\"<\/span>);\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Modern Updates and Best Practices<\/h2>\n\n\n\n<p>Since the original article was written, Microsoft has made several improvements to file system handling in .NET. Here are some updated recommendations:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Use async operations when possible<\/strong> &#8211; For applications that need to remain responsive while checking drive information, especially for network drives:<\/li>\n<\/ol>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">public <span class=\"hljs-keyword\">async<\/span> Task&lt;DriveInfo&#91;]&gt; GetDrivesAsync()\n{\n    <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-keyword\">await<\/span> Task.Run(<span class=\"hljs-function\"><span class=\"hljs-params\">()<\/span> =&gt;<\/span> DriveInfo.GetDrives());\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>Consider using a <\/strong><code>FileSystemWatcher<\/code> for monitoring changes. If you need to monitor drive changes:<\/li>\n<\/ol>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">using System.IO;\n\nFileSystemWatcher watcher = <span class=\"hljs-keyword\">new<\/span> FileSystemWatcher();\nwatcher.Path = @<span class=\"hljs-string\">\"C:\\\";\nwatcher.NotifyFilter = NotifyFilters.DirectoryName;\nwatcher.Filter = \"<\/span>*<span class=\"hljs-string\">\";\nwatcher.Changed += OnChanged;\nwatcher.EnableRaisingEvents = true;\n\nstatic void OnChanged(object sender, FileSystemEventArgs e)\n{\n    \/\/ Check drive information when changes occur\n    DriveInfo drive = new DriveInfo(Path.GetPathRoot(e.FullPath));\n    if (drive.IsReady)\n    {\n        Console.WriteLine($\"<\/span>Drive {drive.Name} has {drive.AvailableFreeSpace \/ <span class=\"hljs-number\">1073741824<\/span>} GB free<span class=\"hljs-string\">\");\n    }\n}<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>Format sizes in human-readable format<\/strong> &#8211; A helper method for better displaying sizes:<\/li>\n<\/ol>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">public <span class=\"hljs-keyword\">static<\/span> string FormatSize(long bytes)\n{\n    string&#91;] suffixes = { <span class=\"hljs-string\">\"B\"<\/span>, <span class=\"hljs-string\">\"KB\"<\/span>, <span class=\"hljs-string\">\"MB\"<\/span>, <span class=\"hljs-string\">\"GB\"<\/span>, <span class=\"hljs-string\">\"TB\"<\/span>, <span class=\"hljs-string\">\"PB\"<\/span> };\n    int counter = <span class=\"hljs-number\">0<\/span>;\n    decimal number = bytes;\n    \n    <span class=\"hljs-keyword\">while<\/span> (<span class=\"hljs-built_in\">Math<\/span>.Round(number \/ <span class=\"hljs-number\">1024<\/span>) &gt;= <span class=\"hljs-number\">1<\/span>)\n    {\n        number = number \/ <span class=\"hljs-number\">1024<\/span>;\n        counter++;\n    }\n    \n    <span class=\"hljs-keyword\">return<\/span> $<span class=\"hljs-string\">\"{number:n1} {suffixes&#91;counter]}\"<\/span>;\n}\n\n<span class=\"hljs-comment\">\/\/ Usage<\/span>\nConsole.WriteLine($<span class=\"hljs-string\">\"Available space: {FormatSize(drive.AvailableFreeSpace)}\"<\/span>);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Common Errors and How to Handle Them<\/h2>\n\n\n\n<p>When working with DriveInfo, you might encounter several exceptions:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>IOException<\/strong>: Can occur when trying to access properties of a drive that&#8217;s not ready<\/li>\n\n\n\n<li><strong>UnauthorizedAccessException<\/strong>: You might not have permissions to access certain drive information<\/li>\n\n\n\n<li><strong>ArgumentException<\/strong>: The drive letter specified doesn&#8217;t exist<\/li>\n<\/ol>\n\n\n\n<p>Here&#8217;s a robust error-handling example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-keyword\">try<\/span>\n{\n    DriveInfo drive = <span class=\"hljs-keyword\">new<\/span> DriveInfo(<span class=\"hljs-string\">\"X\"<\/span>);\n    \n    <span class=\"hljs-keyword\">if<\/span> (drive.IsReady)\n    {\n        Console.WriteLine($<span class=\"hljs-string\">\"Drive format: {drive.DriveFormat}\"<\/span>);\n    }\n    <span class=\"hljs-keyword\">else<\/span>\n    {\n        Console.WriteLine(<span class=\"hljs-string\">\"Drive is not ready.\"<\/span>);\n    }\n}\n<span class=\"hljs-keyword\">catch<\/span> (ArgumentException)\n{\n    Console.WriteLine(<span class=\"hljs-string\">\"The drive letter specified doesn't exist.\"<\/span>);\n}\n<span class=\"hljs-keyword\">catch<\/span> (UnauthorizedAccessException)\n{\n    Console.WriteLine(<span class=\"hljs-string\">\"You don't have permission to access this drive.\"<\/span>);\n}\n<span class=\"hljs-keyword\">catch<\/span> (IOException ex)\n{\n    Console.WriteLine($<span class=\"hljs-string\">\"An I\/O error occurred: {ex.Message}\"<\/span>);\n}\n<span class=\"hljs-keyword\">catch<\/span> (<span class=\"hljs-keyword\">Exception<\/span> ex)\n{\n    Console.WriteLine($<span class=\"hljs-string\">\"An unexpected error occurred: {ex.Message}\"<\/span>);\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Conclusion: Mastering the DriveInfo Class<\/h2>\n\n\n\n<p>The C# DriveInfo class gives you tremendous power to work with drives in your applications. Whether you&#8217;re building system utilities, file managers, or just need to check available space, this class makes it incredibly simple.<\/p>\n\n\n\n<p>Remember these key points:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Always check IsReady before accessing drive properties<\/li>\n\n\n\n<li>Handle exceptions properly for robust applications<\/li>\n\n\n\n<li>Use the DriveType property to distinguish between different types of drives<\/li>\n\n\n\n<li>Format sizes appropriately for a better user experience<\/li>\n<\/ul>\n\n\n\n<p>With these techniques in your toolkit, you&#8217;ll be able to create powerful applications that effectively manage and utilize drive information. Also, consider exploring detailed documentation on <a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/api\/system.io.driveinfo?view=net-9.0\" target=\"_blank\" rel=\"noreferrer noopener\">Microsoft official documentation site<\/a>.<\/p>\n\n\n\n<p>Do you have questions about using the DriveInfo class in your projects? Let me know in the comments!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Frequently Asked Questions<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><em>How do I update the volume label?<\/em><\/h3>\n\n\n\n<p>Set <code>drive.VolumeLabel = \"PROJECTS\"<\/code>\u2014but only on drives supporting labels (NTFS, exFAT). Requires admin on older Windows versions.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><em>Can I monitor space in real-time?<\/em><\/h3>\n\n\n\n<p>Yes. Poll with a <code>System.Timers.Timer<\/code> and call <code>drive.Refresh()<\/code> before reading properties.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><em>What about cross-platform?<\/em><\/h3>\n\n\n\n<p><code>DriveInfo<\/code> works on macOS and Linux; FAT\/EXT file systems report accurately under .NET 8\/9.\u200b<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this beginner-friendly guide, we explore the C# DriveInfo class to enumerate drives, check formats and free space, and handle removable media effortlessly. Through clear code snippets and practical tips, you\u2019ll learn to build robust disk-inspection tools without WMI. Perfect for .NET 6+ developers diving into system I\/O.<\/p>\n","protected":false},"author":1,"featured_media":58462,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[15,4],"class_list":{"0":"post-99","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-programming","8":"tag-net","9":"tag-c-sharp","10":"entry"},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>C# DriveInfo Class: Access Drive Information Like a Pro - CodeSamplez.com<\/title>\n<meta name=\"description\" content=\"Master the C# DriveInfo class to access drive information, check available space, and identify drive types in your .NET applications.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/codesamplez.com\/programming\/drive-info-csharp\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C# DriveInfo Class: Access Drive Information Like a Pro\" \/>\n<meta property=\"og:description\" content=\"Master the C# DriveInfo class to access drive information, check available space, and identify drive types in your .NET applications.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/codesamplez.com\/programming\/drive-info-csharp\" \/>\n<meta property=\"og:site_name\" content=\"CodeSamplez.com\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/codesamplez\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/ranacseruet\" \/>\n<meta property=\"article:published_time\" content=\"2010-11-10T07:58:02+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-04-24T16:47:58+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/codesamplez.com\/wp-content\/uploads\/2010\/11\/c-sharp-drive-info.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1536\" \/>\n\t<meta property=\"og:image:height\" content=\"1024\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"Rana Ahsan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@ranacseruet\" \/>\n<meta name=\"twitter:site\" content=\"@codesamplez\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rana Ahsan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"Article\",\"BlogPosting\"],\"@id\":\"https:\\\/\\\/codesamplez.com\\\/programming\\\/drive-info-csharp#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/codesamplez.com\\\/programming\\\/drive-info-csharp\"},\"author\":{\"name\":\"Rana Ahsan\",\"@id\":\"https:\\\/\\\/codesamplez.com\\\/#\\\/schema\\\/person\\\/a82c3c07205f4bb73d6b3b0906bc328b\"},\"headline\":\"C# DriveInfo Class: Access Drive Information Like a Pro\",\"datePublished\":\"2010-11-10T07:58:02+00:00\",\"dateModified\":\"2025-04-24T16:47:58+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/codesamplez.com\\\/programming\\\/drive-info-csharp\"},\"wordCount\":872,\"commentCount\":5,\"publisher\":{\"@id\":\"https:\\\/\\\/codesamplez.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/codesamplez.com\\\/programming\\\/drive-info-csharp#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/codesamplez.com\\\/wp-content\\\/uploads\\\/2010\\\/11\\\/c-sharp-drive-info.webp\",\"keywords\":[\".net\",\"c#\"],\"articleSection\":[\"Programming\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/codesamplez.com\\\/programming\\\/drive-info-csharp#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/codesamplez.com\\\/programming\\\/drive-info-csharp\",\"url\":\"https:\\\/\\\/codesamplez.com\\\/programming\\\/drive-info-csharp\",\"name\":\"C# DriveInfo Class: Access Drive Information Like a Pro - CodeSamplez.com\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/codesamplez.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/codesamplez.com\\\/programming\\\/drive-info-csharp#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/codesamplez.com\\\/programming\\\/drive-info-csharp#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/codesamplez.com\\\/wp-content\\\/uploads\\\/2010\\\/11\\\/c-sharp-drive-info.webp\",\"datePublished\":\"2010-11-10T07:58:02+00:00\",\"dateModified\":\"2025-04-24T16:47:58+00:00\",\"description\":\"Master the C# DriveInfo class to access drive information, check available space, and identify drive types in your .NET applications.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/codesamplez.com\\\/programming\\\/drive-info-csharp#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/codesamplez.com\\\/programming\\\/drive-info-csharp\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/codesamplez.com\\\/programming\\\/drive-info-csharp#primaryimage\",\"url\":\"https:\\\/\\\/codesamplez.com\\\/wp-content\\\/uploads\\\/2010\\\/11\\\/c-sharp-drive-info.webp\",\"contentUrl\":\"https:\\\/\\\/codesamplez.com\\\/wp-content\\\/uploads\\\/2010\\\/11\\\/c-sharp-drive-info.webp\",\"width\":1536,\"height\":1024,\"caption\":\"C# DriveInfo\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/codesamplez.com\\\/programming\\\/drive-info-csharp#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/codesamplez.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C# DriveInfo Class: Access Drive Information Like a Pro\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/codesamplez.com\\\/#website\",\"url\":\"https:\\\/\\\/codesamplez.com\\\/\",\"name\":\"CODESAMPLEZ.COM\",\"description\":\"Programming And Development Resources\",\"publisher\":{\"@id\":\"https:\\\/\\\/codesamplez.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/codesamplez.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/codesamplez.com\\\/#organization\",\"name\":\"codesamplez.com\",\"url\":\"https:\\\/\\\/codesamplez.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/codesamplez.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/codesamplez.com\\\/wp-content\\\/uploads\\\/2024\\\/10\\\/cropped-favicon.webp\",\"contentUrl\":\"https:\\\/\\\/codesamplez.com\\\/wp-content\\\/uploads\\\/2024\\\/10\\\/cropped-favicon.webp\",\"width\":512,\"height\":512,\"caption\":\"codesamplez.com\"},\"image\":{\"@id\":\"https:\\\/\\\/codesamplez.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/codesamplez\",\"https:\\\/\\\/x.com\\\/codesamplez\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/codesamplez.com\\\/#\\\/schema\\\/person\\\/a82c3c07205f4bb73d6b3b0906bc328b\",\"name\":\"Rana Ahsan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c7a4f88bcf4a55cd1483386318ebecf27359154275a0b355b0ea186676f9f7f?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c7a4f88bcf4a55cd1483386318ebecf27359154275a0b355b0ea186676f9f7f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c7a4f88bcf4a55cd1483386318ebecf27359154275a0b355b0ea186676f9f7f?s=96&d=mm&r=g\",\"caption\":\"Rana Ahsan\"},\"description\":\"Rana Ahsan is a seasoned software engineer and technology leader specialized in distributed systems and software architecture. With a Master\u2019s in Software Engineering from Concordia University, his experience spans leading scalable architecture at Coursera and TopHat, contributing to open-source projects. This blog, CodeSamplez.com, showcases his passion for sharing practical insights on programming and distributed systems concepts and help educate others. Github | X | LinkedIn\",\"sameAs\":[\"https:\\\/\\\/github.com\\\/ranacseruet\",\"https:\\\/\\\/www.facebook.com\\\/ranacseruet\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/ranacseruet\\\/\",\"https:\\\/\\\/x.com\\\/ranacseruet\"],\"url\":\"https:\\\/\\\/codesamplez.com\\\/author\\\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"C# DriveInfo Class: Access Drive Information Like a Pro - CodeSamplez.com","description":"Master the C# DriveInfo class to access drive information, check available space, and identify drive types in your .NET applications.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/codesamplez.com\/programming\/drive-info-csharp","og_locale":"en_US","og_type":"article","og_title":"C# DriveInfo Class: Access Drive Information Like a Pro","og_description":"Master the C# DriveInfo class to access drive information, check available space, and identify drive types in your .NET applications.","og_url":"https:\/\/codesamplez.com\/programming\/drive-info-csharp","og_site_name":"CodeSamplez.com","article_publisher":"https:\/\/www.facebook.com\/codesamplez","article_author":"https:\/\/www.facebook.com\/ranacseruet","article_published_time":"2010-11-10T07:58:02+00:00","article_modified_time":"2025-04-24T16:47:58+00:00","og_image":[{"width":1536,"height":1024,"url":"https:\/\/codesamplez.com\/wp-content\/uploads\/2010\/11\/c-sharp-drive-info.webp","type":"image\/webp"}],"author":"Rana Ahsan","twitter_card":"summary_large_image","twitter_creator":"@ranacseruet","twitter_site":"@codesamplez","twitter_misc":{"Written by":"Rana Ahsan","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/codesamplez.com\/programming\/drive-info-csharp#article","isPartOf":{"@id":"https:\/\/codesamplez.com\/programming\/drive-info-csharp"},"author":{"name":"Rana Ahsan","@id":"https:\/\/codesamplez.com\/#\/schema\/person\/a82c3c07205f4bb73d6b3b0906bc328b"},"headline":"C# DriveInfo Class: Access Drive Information Like a Pro","datePublished":"2010-11-10T07:58:02+00:00","dateModified":"2025-04-24T16:47:58+00:00","mainEntityOfPage":{"@id":"https:\/\/codesamplez.com\/programming\/drive-info-csharp"},"wordCount":872,"commentCount":5,"publisher":{"@id":"https:\/\/codesamplez.com\/#organization"},"image":{"@id":"https:\/\/codesamplez.com\/programming\/drive-info-csharp#primaryimage"},"thumbnailUrl":"https:\/\/codesamplez.com\/wp-content\/uploads\/2010\/11\/c-sharp-drive-info.webp","keywords":[".net","c#"],"articleSection":["Programming"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/codesamplez.com\/programming\/drive-info-csharp#respond"]}]},{"@type":"WebPage","@id":"https:\/\/codesamplez.com\/programming\/drive-info-csharp","url":"https:\/\/codesamplez.com\/programming\/drive-info-csharp","name":"C# DriveInfo Class: Access Drive Information Like a Pro - CodeSamplez.com","isPartOf":{"@id":"https:\/\/codesamplez.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/codesamplez.com\/programming\/drive-info-csharp#primaryimage"},"image":{"@id":"https:\/\/codesamplez.com\/programming\/drive-info-csharp#primaryimage"},"thumbnailUrl":"https:\/\/codesamplez.com\/wp-content\/uploads\/2010\/11\/c-sharp-drive-info.webp","datePublished":"2010-11-10T07:58:02+00:00","dateModified":"2025-04-24T16:47:58+00:00","description":"Master the C# DriveInfo class to access drive information, check available space, and identify drive types in your .NET applications.","breadcrumb":{"@id":"https:\/\/codesamplez.com\/programming\/drive-info-csharp#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/codesamplez.com\/programming\/drive-info-csharp"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codesamplez.com\/programming\/drive-info-csharp#primaryimage","url":"https:\/\/codesamplez.com\/wp-content\/uploads\/2010\/11\/c-sharp-drive-info.webp","contentUrl":"https:\/\/codesamplez.com\/wp-content\/uploads\/2010\/11\/c-sharp-drive-info.webp","width":1536,"height":1024,"caption":"C# DriveInfo"},{"@type":"BreadcrumbList","@id":"https:\/\/codesamplez.com\/programming\/drive-info-csharp#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/codesamplez.com\/"},{"@type":"ListItem","position":2,"name":"C# DriveInfo Class: Access Drive Information Like a Pro"}]},{"@type":"WebSite","@id":"https:\/\/codesamplez.com\/#website","url":"https:\/\/codesamplez.com\/","name":"CODESAMPLEZ.COM","description":"Programming And Development Resources","publisher":{"@id":"https:\/\/codesamplez.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/codesamplez.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/codesamplez.com\/#organization","name":"codesamplez.com","url":"https:\/\/codesamplez.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codesamplez.com\/#\/schema\/logo\/image\/","url":"https:\/\/codesamplez.com\/wp-content\/uploads\/2024\/10\/cropped-favicon.webp","contentUrl":"https:\/\/codesamplez.com\/wp-content\/uploads\/2024\/10\/cropped-favicon.webp","width":512,"height":512,"caption":"codesamplez.com"},"image":{"@id":"https:\/\/codesamplez.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/codesamplez","https:\/\/x.com\/codesamplez"]},{"@type":"Person","@id":"https:\/\/codesamplez.com\/#\/schema\/person\/a82c3c07205f4bb73d6b3b0906bc328b","name":"Rana Ahsan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/5c7a4f88bcf4a55cd1483386318ebecf27359154275a0b355b0ea186676f9f7f?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/5c7a4f88bcf4a55cd1483386318ebecf27359154275a0b355b0ea186676f9f7f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5c7a4f88bcf4a55cd1483386318ebecf27359154275a0b355b0ea186676f9f7f?s=96&d=mm&r=g","caption":"Rana Ahsan"},"description":"Rana Ahsan is a seasoned software engineer and technology leader specialized in distributed systems and software architecture. With a Master\u2019s in Software Engineering from Concordia University, his experience spans leading scalable architecture at Coursera and TopHat, contributing to open-source projects. This blog, CodeSamplez.com, showcases his passion for sharing practical insights on programming and distributed systems concepts and help educate others. Github | X | LinkedIn","sameAs":["https:\/\/github.com\/ranacseruet","https:\/\/www.facebook.com\/ranacseruet","https:\/\/www.linkedin.com\/in\/ranacseruet\/","https:\/\/x.com\/ranacseruet"],"url":"https:\/\/codesamplez.com\/author\/admin"}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/codesamplez.com\/wp-content\/uploads\/2010\/11\/c-sharp-drive-info.webp","jetpack_shortlink":"https:\/\/wp.me\/p1hHlI-1B","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":187,"url":"https:\/\/codesamplez.com\/development\/application-settings-c-sharp","url_meta":{"origin":99,"position":0},"title":"App Config File in C#: Simplify Your Application Settings","author":"Rana Ahsan","date":"December 18, 2010","format":false,"excerpt":"This article provides a practical guide on managing application settings in C#.NET using configuration files. It explains how to store and retrieve single-value settings via the section and handle multiple-value settings through custom configuration sections. By leveraging the ConfigurationManager class and defining custom configuration classes, developers can externalize dynamic values\u2026","rel":"","context":"In &quot;Development&quot;","block_context":{"text":"Development","link":"https:\/\/codesamplez.com\/category\/development"},"img":{"alt_text":"App Config File in C# Application","src":"https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2010\/12\/app-config-c-sharp.webp?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2010\/12\/app-config-c-sharp.webp?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2010\/12\/app-config-c-sharp.webp?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2010\/12\/app-config-c-sharp.webp?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2010\/12\/app-config-c-sharp.webp?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2010\/12\/app-config-c-sharp.webp?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":22969,"url":"https:\/\/codesamplez.com\/programming\/multithreaded-programming-c-sharp","url_meta":{"origin":99,"position":1},"title":"Multithreaded Programming In C#: A Beginners Guide","author":"Rana Ahsan","date":"February 18, 2013","format":false,"excerpt":"In this guide, we explore the essentials of multithreaded programming in C#. Multithreading allows you to run tasks in parallel, improving the performance and responsiveness of your application. By leveraging the Thread and ThreadPool classes, developers can easily implement multithreading for tasks like database queries or UI operations.","rel":"","context":"In &quot;Programming&quot;","block_context":{"text":"Programming","link":"https:\/\/codesamplez.com\/category\/programming"},"img":{"alt_text":"Multithreaded Programming C#","src":"https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2013\/02\/multi-threaded-programming-c-sharp.webp?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2013\/02\/multi-threaded-programming-c-sharp.webp?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2013\/02\/multi-threaded-programming-c-sharp.webp?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2013\/02\/multi-threaded-programming-c-sharp.webp?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2013\/02\/multi-threaded-programming-c-sharp.webp?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2013\/02\/multi-threaded-programming-c-sharp.webp?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":22765,"url":"https:\/\/codesamplez.com\/programming\/serial-port-communication-c-sharp","url_meta":{"origin":99,"position":2},"title":"C# Serial Port Communication: A Complete Guide","author":"Rana Ahsan","date":"February 7, 2013","format":false,"excerpt":"This tutorial provides a comprehensive guide to implementing serial port communication in C# applications. It covers configuring serial port parameters such as baud rate, parity, data bits, and stop bits using the System.IO.Ports.SerialPort class. The article includes code examples demonstrating how to open and close serial ports, send and receive\u2026","rel":"","context":"In &quot;Programming&quot;","block_context":{"text":"Programming","link":"https:\/\/codesamplez.com\/category\/programming"},"img":{"alt_text":"C# Serial Port Communication","src":"https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2013\/02\/c-sharp-serialport-communication.webp?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2013\/02\/c-sharp-serialport-communication.webp?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2013\/02\/c-sharp-serialport-communication.webp?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2013\/02\/c-sharp-serialport-communication.webp?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2013\/02\/c-sharp-serialport-communication.webp?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2013\/02\/c-sharp-serialport-communication.webp?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":711,"url":"https:\/\/codesamplez.com\/development\/wpf-property-grid-tutorial","url_meta":{"origin":99,"position":3},"title":"WPF Property Grid (WPG) Tutorial In C#","author":"Rana Ahsan","date":"April 19, 2011","format":false,"excerpt":"This article provides a beginner-friendly guide to implementing a property grid in WPF applications using C#. It explains how to automatically generate UI controls based on class properties and attributes like Category, DisplayName, and Description. The tutorial includes practical code examples for setting up and customizing the property grid, highlighting\u2026","rel":"","context":"In &quot;Development&quot;","block_context":{"text":"Development","link":"https:\/\/codesamplez.com\/category\/development"},"img":{"alt_text":"WPF Property Grid in C#.NET","src":"https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2011\/04\/wpf-property-grid-c-sharp.webp?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2011\/04\/wpf-property-grid-c-sharp.webp?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2011\/04\/wpf-property-grid-c-sharp.webp?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2011\/04\/wpf-property-grid-c-sharp.webp?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2011\/04\/wpf-property-grid-c-sharp.webp?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2011\/04\/wpf-property-grid-c-sharp.webp?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":22856,"url":"https:\/\/codesamplez.com\/programming\/c-sharp-dictionary-tutorial","url_meta":{"origin":99,"position":4},"title":"C# Dictionary: Complete Guide to Mastering Key-Value Collections","author":"Rana Ahsan","date":"February 12, 2013","format":false,"excerpt":"This tutorial introduces the C# Dictionary collection, a powerful key-value data structure built on a hash table. It covers initializing dictionaries with default values, adding and removing entries, iterating using foreach with KeyValuePair, and merging dictionaries using LINQ. Additionally, it addresses XML serialization challenges and solutions for dictionaries. Ideal for\u2026","rel":"","context":"In &quot;Programming&quot;","block_context":{"text":"Programming","link":"https:\/\/codesamplez.com\/category\/programming"},"img":{"alt_text":"C# Dictionary","src":"https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2013\/02\/c-sharp-dictionary.webp?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2013\/02\/c-sharp-dictionary.webp?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2013\/02\/c-sharp-dictionary.webp?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2013\/02\/c-sharp-dictionary.webp?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2013\/02\/c-sharp-dictionary.webp?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2013\/02\/c-sharp-dictionary.webp?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":482,"url":"https:\/\/codesamplez.com\/programming\/serialize-deserialize-c-sharp-objects","url_meta":{"origin":99,"position":5},"title":"Mastering XML Serialization in C#: A Complete Guide","author":"Rana Ahsan","date":"February 12, 2011","format":false,"excerpt":"This article provides a practical guide to serializing and deserializing C# objects using XML. It demonstrates how to utilize the XmlSerializer and StreamWriter classes to convert objects into XML format and save them to files. Conversely, it explains how to read XML files and reconstruct the original objects using StreamReader.\u2026","rel":"","context":"In &quot;Programming&quot;","block_context":{"text":"Programming","link":"https:\/\/codesamplez.com\/category\/programming"},"img":{"alt_text":"C# XML Serialization","src":"https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2011\/02\/c-sharp-xml-serialization.webp?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2011\/02\/c-sharp-xml-serialization.webp?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2011\/02\/c-sharp-xml-serialization.webp?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2011\/02\/c-sharp-xml-serialization.webp?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2011\/02\/c-sharp-xml-serialization.webp?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2011\/02\/c-sharp-xml-serialization.webp?resize=1400%2C800&ssl=1 4x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/codesamplez.com\/wp-json\/wp\/v2\/posts\/99","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codesamplez.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codesamplez.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codesamplez.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codesamplez.com\/wp-json\/wp\/v2\/comments?post=99"}],"version-history":[{"count":2,"href":"https:\/\/codesamplez.com\/wp-json\/wp\/v2\/posts\/99\/revisions"}],"predecessor-version":[{"id":58463,"href":"https:\/\/codesamplez.com\/wp-json\/wp\/v2\/posts\/99\/revisions\/58463"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codesamplez.com\/wp-json\/wp\/v2\/media\/58462"}],"wp:attachment":[{"href":"https:\/\/codesamplez.com\/wp-json\/wp\/v2\/media?parent=99"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codesamplez.com\/wp-json\/wp\/v2\/categories?post=99"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codesamplez.com\/wp-json\/wp\/v2\/tags?post=99"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}