Example

using System;
using System.IO;

namespace Samples
{
  public class PathTooLongExceptionSample
  {
    public static void Main()
    {
      try
      {
        string p = @"This\Is\A\Very\Long\Path\" +
                   @"But\It\Is\Only\An\Example\";
        string s = @"C:\" + p + p + p + p + p + p +
                   "filename.txt";
        FileStream fs = File.Create(s);
      }
      catch(PathTooLongException e)
      {
        Console.WriteLine("Exception: {0}", e);
      }
    }
  }
}
The output is
 Exception: System.IO.PathTooLongException: The path is too long after being fully qualified. Make sure path is less than 260 characters. at System.IO.Path.nGetFullPathHelper(String path, Char[] invalidPathChars, Char[] whitespaceChars, Char directorySeparator, Char altDirectorySeparator, Boolean fullCheck, String& newPath) at System.IO.Path.GetFullPathInternal(String ...

Get .NET Framework Standard Library Annotated Reference, Volume 1: Base Class Library and Extended Numerics Library now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.