.NET API Reference

PathTooLongException Class

The PathTooLongException class represents an error that occurs when a path or fully qualified file name exceeds the system-defined maximum length.

Namespace

System.IO

Assembly

System.Runtime.dll

Inheritance

System.Object → System.Exception → System.SystemException → System.IO.IOException → System.IO.PathTooLongException

Constructor

public PathTooLongException();
public PathTooLongException(string message);
public PathTooLongException(string message, Exception innerException);

Properties

Example

The following example demonstrates how to catch a PathTooLongException when attempting to create a directory with an excessively long path.

using System;
using System.IO;

class Program
{
    static void Main()
    {
        try
        {
            // Generate a path longer than 260 characters
            string longPath = new string('a', 260);
            Directory.CreateDirectory(longPath);
        }
        catch (PathTooLongException ex)
        {
            Console.WriteLine("Error: " + ex.Message);
        }
    }
}

See Also