System.IO.DirectoryNotFoundException Class

The exception that is thrown when part of a file or directory cannot be found.

See Also: DirectoryNotFoundException Members

Syntax

[System.Runtime.InteropServices.ComVisible(true)]
public class DirectoryNotFoundException : IOException

Remarks

DirectoryNotFoundException uses the HRESULT COR_E_DIRECTORYNOTFOUND which has the value 0x80070003. Note that DirectoryNotFoundException is also thrown when COM interop programs see the HRESULT STG_E_PATHNOTFOUND, which has the value 0x80030003.

If your code does not have System.Security.Permissions.FileIOPermissionAttribute.PathDiscovery permission, the error message for this exception may only contain file or directory names instead of fully qualified paths.

Thread Safety

All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe.

Example

The following example demonstrates an error that causes the System.IO.DirectoryNotFoundException exception to be thrown. In this case, the /Mistake/examples/ directory does not exist and therefore cannot be located.

C# Example

using System;
using System.IO;
class DirectoryNotFoundExample {
 public static void Main () {
 string badPath = "/Mistake/examples/";
 try {
 Directory.GetFiles(badPath);
 }
 catch (DirectoryNotFoundException e) {
 Console.WriteLine("Caught: {0}",e.Message);
 }
 }
}

The output is

Caught: Could not find a part of the path "C:\Mistake\examples".

Requirements

Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0